思路:要一边转化字符串,一边取整,或者求余!!!!
#include<stdio.h>
#include<string.h>
#define N 800
int main(){
char s1[N];
char ch;
long i, temp, sum, l, num, j, s2[N];
while (scanf("%s %c %ld", s1, &ch, &num) != EOF){
memset(s2, 0, sizeof(s2));
l = strlen(s1);
sum = 0;
if (ch == '/'){
temp = 0;
for(i = 0; i < l; i++){
temp = temp * 10 + s1[i] - '0';
if (temp >= num){
++sum;
s2[sum] = temp / num;
temp %= num;
}
else
++sum;
}
j = 1;
while ((s2[j] == 0) && (j < sum))
j++;
for(i = j; i <= sum; i++)
printf("%ld", s2[i]);
printf("\n");
}
else{
for(i = 0; i < l; i++){
sum = sum * 10 + s1[i] - '0';
sum %= num;
}
printf("%ld\n", sum);
}
}
return 0;
}