1007: younger brother's job time limit: 1 sec memory limit: 128 MB
Submitted: 3 solution: 3
[Submit] [Status] [discussion version] Description
Your younger brother has just completed the assignment of "adding and subtracting less than 100". Please check it for him. The format of each question (including the answer of the younger brother) isA+B=COrA-B=C, WhereAAndBIs a non-negative integer not greater than 100 given in the job;CThe answer is calculated by the younger brother. It may be a non-negative integer not greater than 200, or a single character "? ", Indicating that he will not calculate.
Input
The input file contains no more than 100 lines and ends with a file Terminator. Each line contains a question. The format must comply with the preceding rules and does not contain any blank characters. All input integers do not contain leading 0.
Output
The output contains only one row, which contains a non-negative integer, that is, the number of correct answers.
Sample Input
1+2=33-1=56+7=?99-0=99
Sample output
2
Prompt
Source
Hunan sixth College Computer Program Design Competition
I refreshed another question and failed to process the last character at the beginning, causing an exception. This question mainly deals with the last character, you can enter the preceding information directly or change it to another question. When there is an error, we can make a mark;
The following code is used:
# Include <cstdio> # include <cstring> int main () {int A, B, C, I; char op, s [10]; int COUNT = 0; while (scanf ("% d % C % d = % s", & A, & OP, & B, S )! = EOF) {I = 0; If (s [I]> = '0' & S [I] <= '9 ') // process the last number c {c = 0; while (s [I]> = '0' & S [I] <= '9 ') {C = C * 10 + (s [I]-'0'); I ++ ;}} else c =-1; // error mark if (OP = '+' & C = a + B) | (OP = '-' & C = a-B) Count ++;} printf ("% d \ n", count); Return 0 ;}The following is a bit tedious to write;
# Include <cstdio> # include <cstring> int main () {int A, B, C, I; char op, s [10]; int COUNT = 0; while (scanf ("% s", S )! = EOF) {I = 0; a = 0; B = 0; while (s [I]> = '0' & S [I] <= '9 ') {A = A * 10 + (s [I]-'0'); I ++;} op = s [I]; I ++; while (s [I]> = '0' & S [I] <= '9 ') {B = B * 10 + (s [I]-'0'); I ++;} I ++; if (s [I]> = '0' & S [I] <= '9') {c = 0; while (s [I]> = '0' & S [I] <= '9 ') {C = C * 10 + (s [I]-'0'); I ++ ;}} else c =-1; // error mark if (OP = '+' & C = a + B) | (OP = '-' & C = a-B) Count ++;} printf ("% d \ n", count); Return 0 ;}The idea is still very simple. I have a problem with water every day. I haven't done it for a long time. I have to practice it and start to do it in a short time ~