// Test1063-弟弟的作业.cpp: 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <stdlib.h> int main() { int result = 0; while (1) { char list[12] = {}; scanf_s("%s", list, 10); if (list[1] =='') break; int middle = 0; int sumpos = 0; int length = 0; int a, b, temp_sum,sum = 0; for (int i = 0;i<10; i++) { if ((list[i] == '+') || (list[i] == '-')) middle = i; if (list[i] == '=') sumpos = i; if (list[i] == '') length = i; } if (list[sumpos + 1] == '?') continue; if((middle-0)==2) { //printf("%d %d ", atoi(&list[0]), atoi(&list[1])); //a= atoi(&list[0])*10+atoi(&list[1]); a = atoi(&list[0]); }else a= atoi(&list[0]); if ((sumpos - middle - 1) == 2) { //b = atoi(&list[middle + 1]) * 10 + atoi(&list[middle+2]); b = atoi(&list[middle + 1]); } else b = atoi(&list[middle + 1]); if ((length - sumpos - 1) == 3) //sum = atoi(&list[sumpos + 1]) * 100 + atoi(&list[sumpos + 2]) * 10 + atoi(&list[sumpos + 3]); sum = atoi(&list[sumpos + 1]); else if ((length - sumpos - 1) == 2) //sum = atoi(&list[sumpos + 1]) * 10 + atoi(&list[sumpos + 2]); sum = atoi(&list[sumpos + 1]); else sum = atoi(&list[sumpos + 1]); if (list[middle] == '+') temp_sum = a + b; if (list[middle] == '-') temp_sum = a - b; if (temp_sum== sum) result++; printf("%s ", list); } printf("%d ", result); //while ((c = getchar()) != EOF) //{ // putchar(c); //} return 0; }
1 1+2=3 2 3-1=5 3 6+7=13 4 99-0=? 5 99-0=99 6 0 7 3 8 请按任意键继续. . .