2445 小学数学

﹏ヽ暗。殇╰゛Y 2022-05-26 05:35 312阅读 0赞

小学数学

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

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

Input

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

Output

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

Sample Input

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

Sample Output

  1. 1
  2. import java.util.*;
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner cin = new Scanner(System.in);
  6. int count =0;
  7. while(cin.hasNext()) {
  8. int []a=new int [10];
  9. int num=0;
  10. String str = cin.next();
  11. String []str1 = str.split("-|\\+|=");
  12. char str2[] = str.toCharArray();
  13. char ch = 0;
  14. for(int i=0;i<str.length();i++) {
  15. if(str2[i]=='+') {
  16. ch = '+';
  17. }
  18. else if(str2[i]=='-') {
  19. ch = '-';
  20. }
  21. }
  22. if(str1.length==3) {
  23. if(ch=='+') {
  24. if(!str1[2].equals("?")) {
  25. a[0]=Integer.parseInt(str1[0]);
  26. a[1]=Integer.parseInt(str1[1]);
  27. a[2]=Integer.parseInt(str1[2]);
  28. if(a[0]+a[1]==a[2]) {
  29. count++;
  30. }
  31. }
  32. }
  33. else if(ch=='-') {
  34. if(!str1[2].equals("?")) {
  35. a[0]=Integer.parseInt(str1[0]);
  36. a[1]=Integer.parseInt(str1[1]);
  37. a[2]=Integer.parseInt(str1[2]);
  38. if(a[0]-a[1]==a[2]) {
  39. count++;
  40. }
  41. }
  42. }
  43. }
  44. }
  45. System.out.println(count);
  46. cin.close();
  47. }
  48. }

发表评论

表情:
评论列表 (有 0 条评论,312人围观)

还没有评论,来说两句吧...

相关阅读

    相关 小学数学

    Problem Description 今年中秋节,大宝哥带着一盒月饼去看望小学数学老师。碰巧数学老师在指导他的学生“100以内的加减法”,由于老师要指导很多个小朋友,所以经