Description
今年中秋节,大宝哥带着一盒月饼去看望小学数学老师。碰巧数学老师在指导他的学生“100以内的加减法”,由于老师要指导很多个小朋友,所以经常会忙不过来,于是老师便请大宝帮忙检查下小朋友们的作业情况,并统计出每个小朋友做对了几道题。其中每道算术题的格式为a+b=c、a-b=c、a+b=?、a-b=? 中的一种,最后的问号表示这个小朋友不会计算这道题。在检查作业的过程中,大宝发现他经常算错题目而且会数错个数。所以他想请你帮忙写个程序来统计小朋友做对题目的个数。
Input
输入包含多组测试数据,每组有一行,每行为一道加法或减法算式,数据格式保证符合上述格式,不包含任何其他字符且所有整数均不包含前导0。其中(0≤a,b≤100,0≤c≤200)。
Output
输出只有一行,包含一个整数,即等式成立的个数。
Sample
Input
2+2=3
3-1=2
6+7=?
99-0=?
Output
1
Hint
import java.util.Scanner;
class Math1 {
String str;
public Math1(String str) {
this.str=str;
}
public boolean judge() {
String ch[] = str.split("\\D"); //数字单独存放
if(ch.length<3)
return false;
int a,b,c;
a=Integer.parseInt(ch[0]);
b=Integer.parseInt(ch[1]);
c=Integer.parseInt(ch[2]);
boolean flag; //判断 + -
if(str.contains("+"))
flag = true;
else
flag = false;
if(flag) {
if(a+b==c)
return true;
else
return false;
}
else {
if(a-b==c)
return true;
else
return false;
}
}
}
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int cnt = 0;
while(input.hasNext()) {
String str = input.next();
Math1 math = new Math1(str);
if(math.judge())
cnt++;
}
System.out.println(cnt);
input.close();
}
}