版权声明:我的GitHub:https://github.com/617076674。真诚求星! https://blog.csdn.net/qq_41231926/article/details/83216522
我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC
原题链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805312417021952
题目描述:
知识点:数据越界
思路:用long型变量保存输入值,以防越界
时间复杂度是O(n),其中n为输入的数据对数。空间复杂度是O(1)。
C++代码:
#include<iostream>
using namespace std;
int main() {
int count;
cin >> count;
long num1 = 0;
long num2 = 0;
long num3 = 0;
for (int i = 1; i <= count; i++) {
cin >> num1 >> num2 >> num3;
if (num1 + num2 > num3) {
cout << "Case #" << i << ": " << "true" << endl;
} else {
cout << "Case #" << i << ": " << "false" << endl;
}
}
}
C++解题报告:
JAVA代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = Integer.parseInt(scanner.nextLine());
for (int i = 1; i <= count; i++) {
String[] strings = scanner.nextLine().split("\\s+");
Long[] nums = new Long[3];
for(int j = 0; j < 3; j++){
nums[j] = Long.parseLong(strings[j]);
}
if(nums[0] + nums[1] > nums[2]){
System.out.print("Case #" + i + ": " + true);
}else{
System.out.print("Case #" + i + ": " + false);
}
if(i != count){
System.out.println();
}
}
}
}
JAVA解题报告: