uva10494 - If We Were a Child Again
题目 :http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=276
一开始WA了好多遍后来发现是自己的少了中间为零的判断~
#include<stdio.h> #include<string.h> int main() { char s[1000],o; long a,res[1000]; while(scanf("%s %c %ld",s,&o,&a) != EOF) { long len,num,i,j,count; num = 0; len = strlen(s); count = 0; int leap; if(o == '/') { num = 0; leap = 0; for(i = 0;i < len;i++) { num = num*10 + s[i]-'0'; if(num/a && leap == 0) { res[count++] = num/a; num = num%a; leap = 1; } else if(leap) { res[count++] = num/a; num = num%a; } } if(count == 0) res[count++] = 0; } else { for(i = 0;i < len;i++) { num = num*10 + s[i]-'0'; num = num%a; } res[count++] = num; } for(i = 0;i < count;i++) printf("%ld",res[i]); puts(""); } return 0; }