思路: 采取一种, 边取余边取整的方法, 让这题变的简单许多~
#include<stdio.h>
#include<string.h> int main() {
long long mod;
long long k, tmp;
int len;
int ans[10010];
char num[10010], ch[2];
while(scanf("%s%s%lld", num, ch, &mod) != EOF) {
len = strlen(num);
k = 0;
tmp = 0;
memset(ans, 0, sizeof(ans));
for(int i = 0; i < len; i++) {
tmp = tmp * 10 + num[i] - '0';
ans[k++] = tmp / mod; //此步导致ans有前导0, 后续要判断
tmp = tmp % mod;
}
if(ch[0] == '/') {
int pos;
for(pos = 0; pos < 10010; pos++)
if(ans[pos])
break; //从头判起, 直到第一个不为0的位置
if(pos == 10010)
printf("0");
else
for(int i = pos; i < k; i++)
printf("%d", ans[i]);
printf("\n");
}
else
printf("%lld\n", tmp);
}
return 0;
}