UVA 10494 - If We Were a Child Again

什么也不说了,哗哗的。。。。(数据尽量考虑全面):

代码如下:

#include<stdio.h>
#include<string.h>
#define MAXN 200000
char a[MAXN], f[2];
long long s[MAXN];
long long x, y;
void solve()
{
memset(s,0,sizeof(s));
int len = strlen(a);
int p = -1;
y = 0;
for(int i = 0; i < len; i ++)
{
y = y *10 + (a[i] - '0');//printf("y=%lld\n",y);
s[++p] = y / x;//printf("p=%d s[p]=%lld\n",p,s[p]);
y %= x;
}
if(f[0] == '/')
{
int i;
for(i = 0; i < MAXN; i ++)
if(s[i]) break;//printf("i = %d\n",i);
if(i == MAXN) printf("0");
else
for(int j = i; j < len; j ++)
printf("%lld",s[j]);
printf("\n");
}
if(f[0] == '%')
printf("%lld\n",y);
}
void input()
{
while(scanf("%s%s%lld",a,f,&x) == 3)
{//printf("a=%s f=%s x=%lld\n",a,f,x);
solve();
}
}
int main()
{
input();
return 0;
}



posted on 2012-03-01 00:21  BFP  阅读(214)  评论(0编辑  收藏  举报