3 条题解
-
0
(访客模式)Guest
-
3
LightOJ官方:
#include <bits/stdc++.h> /** * Returns the total number of problems. * * @param a denotes the number of problems in the first computer * @param b denotes the number of problems in the second computer */ int sum(int a, int b) { return a+b; // Implement this method } /** * Takes care of the problem input and output. */ int main() { int cases; scanf("%d", &cases); for (int caseno = 1; caseno <= cases; ++caseno) { int a, b; scanf("%d %d", &a, &b); printf("Case %d: %d\n", caseno, sum(a, b)); } return 0; }
-
2
题目描述
给定两台计算机中存储的问题数量,计算它们的总和。每台计算机中的问题数量都是非负整数且不超过10,且问题不重复。
输入格式
- 第一行输入一个整数T(1 ≤ T ≤ 125),表示测试用例的数量
- 接下来T行,每行包含两个整数a和b,分别表示两台计算机中的问题数量
输出格式
对于每个测试用例,输出一行"Case X: Y",其中X是测试用例编号(从1开始),Y是a和b的和
解题思路
- 读取测试用例数量T
- 循环处理每个测试用例:
- 读取两个整数a和b
- 计算它们的和
- 按照指定格式输出结果
示例代码
T = int(input()) for i in range(1, T + 1): a, b = map(int, input().split()) print(f"Case {i}: {a + b}")
复杂度分析
-
时间复杂度:O(T),每个测试用例的处理时间是常数时间
-
空间复杂度:O(1),只使用了固定数量的变量
注意事项
-
输出格式必须严格匹配"Case X: Y"的格式
-
编号X从1开始
-
不需要考虑大数问题,因为a和b都不超过10
- 1
信息
- ID
- 605
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 14
- 已通过
- 4
- 上传者