http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1435
因为除数是int型以内的,所以直接对被除数扫一遍即可,处理好边界,做好测试就会AC(long long用%lld输出)
WA了依次,PE(用%I64d输出)了一次。
// 15:51 - 16:14 # include <stdio.h> # include <string.h> char d[100005]; char op[5]; int dr; int main() { while (scanf("%s%s%d", d, op, &dr) != EOF) { long long int dd = 0; bool first = true; for (int i = 0; d[i]; ++i) { dd = dd*10 + (d[i]-'0'); if (dd >= dr) first = false; if (op[0] == '/' && ((dd>=dr) || dd<dr&&!first)) printf("%d", dd/dr); dd %= dr; } if (op[0] == '%') printf("%lld", dd); // 用%d也行,因为取模的结果要小于除数,也在int型以内 else if (first) printf("0"); printf(" "); } return 0; }