当前位置:编程学习 > C/C++ >>

UVa10494 - If We Were a Child Again

C++代码:
 
#include <cstdio>  
#include <cstring>  
const int maxsize=10000000;  
char s[maxsize],ans[maxsize];  
int main()  
{  
    char c;  
    long long b,a;  
    memset(s,0,maxsize);  
    while(scanf("%s %c %lld",s,&c,&b)!=EOF)  
    {  
        memset(ans,0,maxsize);  
        int i;  
        a=0;  
        int j=0;  
        int len=strlen(s);  
        for(i=0;i<len;++i)  
        {  
            a=a*10+s[i]-'0';  
            ans[j++]=a/b+'0';  
            a=a%b;  
        }  
        if(c=='%')  
            printf("%lld\n",a);  
        else  
        {  
            i=0;  
            while(ans[i]=='0')++i;  
            if(ans[i]==0)--i;  
            for(;i<=j-1;++i)  
                printf("%c",ans[i]);  
            printf("\n");  
        }  
    }  
    return 0;  
}  

 

 
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,