Problem Description
During the Mid-Autumn Festival this year, Brother Dabao took a box of moon cakes to visit the elementary school math teacher. It happened that the math teacher was instructing his students on "addition and subtraction within 100". Since the teacher has to instruct many children, he was often overwhelmed, so the teacher asked Dabao to help check the children's homework and counted each child's homework. A child got a few questions right. The format of each arithmetic question is one of a+b=c, ab=c, a+b=?, ab=?. The question mark at the end indicates that the child will not calculate this question. In the process of checking the homework, Dabao found that he often miscalculated the questions and counted the wrong number. So he wants to ask you to help write a program to count the number of correct questions the children do.
Input
import java.util. *; public class Main { public static void main(String args[]){ Scanner cin = new Scanner(System.in); int sum = 0; while(cin.hasNext()){ String s = cin.next(); String f1[] = s.split("\\D+"); try{ int a = Integer.parseInt(f1[0]); int b = Integer.parseInt(f1[1]); int c = Integer.parseInt(f1[2]); String f2[] = s.split("\\d+"); char f = f2[1].charAt(0); if(f == '+'){ if(a + b == c){ sum++; } }else if(f == '-'){ if(a - b == c){ sum++; } } }catch(Exception e){ } } System.out.println(sum); } }
00)。
Output
Sample Input
2+2=33-1=26+7=?99-0=?
Sample Output
1