NYOJ 663 younger brother's homework

Source: Internet
Author: User

Younger brother job time limit: 1000 MS | memory limit: 65535 KB difficulty: 1

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.

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.
The output contains only one row, which contains a non-negative integer, that is, the number of correct answers.
Sample Input
1+2=3
3-1=5
6+7=?
99-0=99
Sample output
2
Simple question!
AC code:
#include
    
     int main(){int count=0,i,a,b,c;char str[10],op;while(~scanf("%s",str)){i=0;a=0;while(str[i]>='0'&&str[i]<='9'){a=a*10+(str[i]-'0');i++;}op=str[i];i++;b=0;while(str[i]>='0'&&str[i]<='9'){b=b*10+(str[i]-'0');i++;}i++;if(str[i]>='0'&&str[i]<='9'){c=0;while(str[i]>='0'&&str[i]<='9'){c=c*10+(str[i]-'0');i++;}}elsec=-1;if(((op=='+')&&(a+b==c))||((op=='-')&&(a-b==c)))count++;}printf("%d\n",count);return 0;}
    


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.