标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10724 | Accepted: 3980 |
123 456
555 555
123 594
0 0
No carry operation.
3 carry operations.
1 carry operation.
大坑
CODE:
#include <iostream> #include <cstdio> #include <cstdio> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --) #define MAX_N 10 + 5 using namespace std; char a[MAX_N], b[MAX_N]; int int_a[MAX_N], int_b[MAX_N], la, lb; int main(){ while(scanf("%s%s", a + 1, b + 1) != EOF){ if(a[1] == ‘0‘ && b[1] == ‘0‘) break; memset(int_a, 0, sizeof(int_a)); memset(int_b, 0, sizeof(int_b)); la = strlen(a + 1), lb = strlen(b + 1); REP(i, 1, la) int_a[la - i + 1] = a[i] - ‘0‘; REP(i, 1, lb) int_b[lb - i + 1] = b[i] - ‘0‘; int i = 1, x = 0, res = 0; while(i <= la || i <= lb){ x = int_a[i] + int_b[i] + x; x /= 10; if(x != 0) res ++; i ++; } if(res == 0) printf("No carry operation.\n"); else if(res == 1) printf("%d carry operation.\n", res); else printf("%d carry operations.\n", res); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ALXPCUN/p/4543169.html