参考代码:
import java.util.*;
public class Main {
public static void main(String[] args) {
int count=0;
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) //读取到以文件结尾
{
String str1=sc.next();
int opIndex; //读取'+'、'-'、' ='的下标,从而得到a b c的字符串
if(str1.indexOf('+')!=-1)
opIndex=str1.indexOf('+');
else
opIndex=str1.indexOf('-');
int eqIndex=str1.indexOf('=');
String astr=str1.substring(0,opIndex); //将记录a b c的字符串转换成int
String bstr=str1.substring(opIndex+1,eqIndex);
String cstr=str1.substring(eqIndex+1);
int a=Integer.parseInt(astr);
int b=Integer.parseInt(bstr);
int c;
if(str1.charAt(eqIndex+1)!='?')
c=Integer.parseInt(cstr);
else
continue;
char op=str1.charAt(opIndex);
if(op=='+'&&c==a+b)
count++;
if(op=='-'&&c==a-b)
count++;
}
System.out.println(count);
}
}
0.0分
0 人评分
数列 (C++代码)浏览:664 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:1031 |
C语言程序设计教程(第三版)课后习题9.4 (Java代码)浏览:1417 |
A+B for Input-Output Practice (C++代码)浏览:608 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:601 |
校门外的树 (C语言代码)浏览:693 |
sizeof的大作用 (C语言代码)浏览:1449 |
1126题解浏览:585 |
矩阵乘方 (C语言代码)浏览:1023 |
星期判断机 (C语言代码)浏览:859 |