解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class C1073 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = 0; while(sc.hasNext()){ String str = sc.nextLine(); if(str.indexOf("?") == -1){ //会做的情况 int indexOp = str.indexOf("+"); int indexEqual = str.indexOf("="); int rs = 0; if(indexOp != -1){ //加法题 rs = Integer.valueOf(str.substring(0, indexOp)) + Integer.valueOf(str.substring(indexOp+1, indexEqual)); }else{//减法题 indexOp = str.indexOf("-"); rs = Integer.valueOf(str.substring(0, indexOp)) - Integer.valueOf(str.substring(indexOp+1, indexEqual)); } int checkRs = Integer.valueOf(str.substring(str.indexOf("=")+1)); if(rs == checkRs) count++; } } System.out.println(count); sc.close(); } }
0.0分
6 人评分