小学数学

来源:互联网 发布:点滴记忆源码 编辑:程序博客网 时间:2024/04/26 05:29

小学数学

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

今年中秋节,大宝哥带着一盒月饼去看望小学数学老师。碰巧数学老师在指导他的学生“100以内的加减法”,由于老师要指导很多个小朋友,所以经常会忙不过来,于是老师便请大宝帮忙检查下小朋友们的作业情况,并统计出每个小朋友做对了几道题。其中每道算术题的格式为a+b=c、a-b=c、a+b=?、a-b=? 中的一种,最后的问号表示这个小朋友不会计算这道题。在检查作业的过程中,大宝发现他经常算错题目而且会数错个数。所以他想请你帮忙写个程序来统计小朋友做对题目的个数。

Input

 输入包含多组测试数据,每组有一行,每行为一道加法或减法算式,数据格式保证符合上述格式,不包含任何其他字符且所有整数均不包含前导0。其中(0≤a,b≤100,0≤c≤200)。

Output

 输出只有一行,包含一个整数,即等式成立的个数。

Example Input

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

Example Output

1
import java.util.Scanner;public class Main{public static void main(String[] args){          Scanner reader = new Scanner(System.in);             int num = 0;         while(reader.hasNext()){                 String st = reader.nextLine();         int a = st.indexOf("+");         int p = st.indexOf("-");         if(a >= 0){         String ss = st.substring(0,a);         int b = st.indexOf("=");         String ssr = st.substring(a+1,b);         String s1 = st.substring(b+1,st.length());         if(!s1.equals("?")){         int c = Integer.parseInt(ss);         int d = Integer.parseInt(ssr);         int e = Integer.parseInt(s1);         if(c + d == e){         num++;         }         }         }         else if(p >= 0){         String ss = st.substring(0,p);         int b = st.indexOf("=");         String ssr = st.substring(p+1,b);         String s1 = st.substring(b+1,st.length());         if(!s1.equals("?")){         int c = Integer.parseInt(ss);         int d = Integer.parseInt(ssr);         int e = Integer.parseInt(s1);         if(c - d == e){         num++;         }         }         }         }         System.out.println(num);             reader.close();         }               }          import java.util.Scanner;   public class Main {    public static void main(String args[]){  Scanner reader = new Scanner(System.in);  String s;  int sum = 0;  while(reader.hasNext()){     s = reader.nextLine();     if(!s.contains("?")){  if(s.contains("+")){  int c = s.indexOf("+");  int d = s.indexOf("=");  String s1 = s.substring(0,c);  String s2 = s.substring(c+1,d);  String s3 = s.substring(d+1,s.length());  int a = Integer.parseInt(s1);  int b = Integer.parseInt(s2);  int e = Integer.parseInt(s3);  if(a + b == e){  sum++;  }  }  else if(s.contains("-")){  int c = s.indexOf("-");  int d = s.indexOf("=");  String s1 = s.substring(0,c);  String s2 = s.substring(c+1,d);  String s3 = s.substring(d+1,s.length());  int a = Integer.parseInt(s1);  int b = Integer.parseInt(s2);  int e = Integer.parseInt(s3);  if(a - b == e){  sum++;  }  }  }  }  System.out.println(sum);  }  }      
0 0