UVA 10494 - If We Were a Child Again(高精度除法和取余)

没做,没感觉,做这类题提不起劲
#include <stdio.h> #include <string.h> long long p[10001]; char num[10001]; int main() { long long i,j,k,len,n,mod; char lat[3]; while(scanf("%s%s%lld",num,lat,&n)!=EOF) { memset (p,0,sizeof(p)); len = strlen(num); for(i = 0;i <= len-1;i ++) { p[len-i-1] = num[i] - '0'; } if(lat[0] == '/') { for(i = len-1;i >= 0;i --) { if(p[i]%n == 0) { p[i] = p[i]/n; } else { if(i-1>=0) p[i-1] += (p[i]%n)*10; p[i] = p[i]/n; } } j = 0; for(i = len-1;i >= 0;i --) { if(p[i] != 0) j = 1; if(j) printf("%lld",p[i]); } if(j == 0) printf("0"); printf("\n"); } else if(lat[0] == '%') { j = 1; k = 1; mod = p[0]%n; for(i = 1;i <= len-1;i ++) { k = k * 10 % n; if(p[i] != 0) { mod += (k*p[i])%n; mod = mod % n; } } printf("%lld\n",mod%n); } } return 0; }

 

posted @ 2012-06-28 22:53  godjob  Views(179)  Comments(0Edit  收藏  举报