标签:tin strlen case cas ring .com div return for
2017-07-172017-07-172017-07-17
#include<stdio.h> #include<string.h> int main() { char ch1[1000], ch2[1000]; int num1[1000], num2[1000]; int i, j, max, n, k, flag = 0; scanf("%d", &n); for (k = 0; k<n; k++) { scanf("%s", ch1); scanf("%s", ch2); max = strlen(ch1); if (max<strlen(ch2)) max = strlen(ch2); for (i = 0; i <= max; i++) { num1[i] = 0; num2[i] = 0; } for (i = strlen(ch1) - 1, j = 0; i >= 0; i--) { num1[j++] = ch1[i] - ‘0‘; } for (i = strlen(ch2) - 1, j = 0; i >= 0; i--) { num2[j++] = ch2[i] - ‘0‘; } for (i = 0; i <= max; i++) { num1[i] += num2[i]; if (num1[i]>9) { num1[i] -= 10; num1[i + 1]++; } } printf("Case %d:\n%s + %s = ", k + 1, ch1, ch2); for (i = max - 1; i >= 0; i--) { if (num1[i] == 0 && flag == 0) continue; flag = 1; printf("%d", num1[i]); } if (k != n - 1) printf("\n\n"); else printf("\n"); } return 0; }
标签:tin strlen case cas ring .com div return for
原文地址:http://www.cnblogs.com/edych/p/7193156.html