题目描述:
代码实现:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void swap(char*s, int i, int j) {
char c = s[i];
s[i] = s[j];
s[j] = c;
}
void reverse(char* s, int i, int j) {
while (i < j) {
swap(s, i++, j--);
}
}
int main() {
int a = 0;
int b = 0;
int n = 0;
printf("please input n(n >0 && n <= 10000):\n");
scanf("%d", &n);
while (n--) {
printf("please input a and b:\n");
scanf("%d%d", &a, &b);
char x[128] = {0};
char y[128] = {0};
char z[128] = {0};
int sum = a + b;
itoa(a, x, 10);
itoa(b, y, 10);
itoa(sum, z, 10);
int lenx = strlen(x);
int leny = strlen(y);
int lenz = strlen(z);
reverse(x, 0, lenx - 1);
reverse(y, 0, leny - 1);
reverse(z, 0, lenz - 1);
int ra = atoi(x);
int rb = atoi(y);
int rsum = atoi(z);
if (ra + rb == rsum) {
printf("%d + %d = %d\n", a, b, sum);
} else {
printf("none\n");
}
}
return 0;
}
运行结果: