primary Mathematics

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

 The input contains multiple sets of test data, each set has one line, and each line is an addition or subtraction formula. The data format is guaranteed to conform to the above format, does not contain any other characters and all integers do not contain leading 0s. where (0≤a, b≤100, 0≤c≤2
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

 The output is only one line containing an integer, the number of equals that hold.

Sample Input

2+2=33-1=26+7=?99-0=?

Sample Output

1

Hint

 

Source


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324735060&siteId=291194637