OJ中循环处理多组输入数据
输入描述:
输入包括两个正整数a,b(1 <= a, b <= 1000),输入数据包括多组。
python
1 import sys 2 for line in sys.stdin: 3 a = line.split() 4 print(int(a[0])+int(a[1])) 5 6 7 8 9 while True: 10 try: 11 a = input().split() 12 print(int(a[0]) + int(a[1])) 13 except: 14 break
java
1 import java.util.Scanner; 2 3 // 注意类名必须为 Main, 不要有任何 package xxx 信息 4 public class Main { 5 public static void main(String[] args) { 6 Scanner in = new Scanner(System.in); 7 // 注意 hasNext 和 hasNextLine 的区别 8 while (in.hasNextInt()) { // 注意 while 处理多个 case 9 int a = in.nextInt(); 10 int b = in.nextInt(); 11 System.out.println(a + b); 12 } 13 } 14 }
1 import java.io.BufferedReader; 2 import java.io.InputStreamReader; 3 4 public class Main { 5 public static void main(String[] strr) throws Exception { 6 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 7 String str = null; 8 while ((str=br.readLine())!=null){ 9 String[] nums = str.split(" "); 10 int a = Integer.parseInt(nums[0]); 11 int b = Integer.parseInt(nums[1]); 12 System.out.println(a+b); 13 } 14 } 15 }
c++
#include <iostream> using namespace std; int main() { int n1; while(cin >> n1){ int n2; cin >> n2; cout << n1 + n2 << endl; } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构