输入第1行给出正整数T(<=10),是测试用例的个数。随后给出T组测试用例,每组占一行,顺序给出A、B和C。整数间以空格分隔。
对每组测试用例,在一行中输出“Case #X: true”如果A+B>C,否则输出“Case #X: false”,其中X是测试用例的编号(从1开始)。
4<br/>1 2 3<br/>2 3 4<br/>2147483647 0 2147483646<br/>0 -2147483648 -2147483647
Case #1: false<br/>Case #2: true<br/>Case #3: true<br/>Case #4: false
/**
* A+B和C (15)
* 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)
* 题目描述
* 给定区间[-2的31次方, 2的31次方]内的3个整数A、B和C,请判断A+B是否大于C。
* 输入描述:
* 输入第1行给出正整数T(<=10),是测试用例的个数。随后给出T组测试用例,每组占一行,顺序给出A、B和C。整数间以空格分隔。
* 输出描述:
* 对每组测试用例,在一行中输出“Case #X: true”如果A+B>C,否则输出“Case #X: false”,其中X是测试用例的编号(从1开始)。
* 输入例子:
* 4
* 1 2 3
* 2 3 4
* 2147483647 0 2147483646
* 0 -2147483648 -2147483647
* 输出例子:
* Case #1: false
* Case #2: true
* Case #3: true
* Case #4: false
*
* @author shijiacheng
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i = 0; i < T; i++) {
BigInteger A = sc.nextBigInteger();
BigInteger B = sc.nextBigInteger();
BigInteger C = sc.nextBigInteger();
BigInteger sum = A.add(B);
if (sum.compareTo(C) > 0) {
System.out.println("Case #" + (i + 1) + ": true");
} else {
System.out.println("Case #" + (i + 1) + ": false");
}
}
}
}
就跟我说 1 2147483648 2147483648 2147483648 过不去 然而我这能过去啊... 什么鬼
import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); boolean[] result = new boolean[n]; for(int i = 0; i < n; i++) { long a = sc.nextLong(); long b = sc.nextLong(); long c = sc.nextLong(); if((c-a)<b) result[i] = true; else result[i] = false; } for(int i = 0; i < n; i++) System.out.println("Case #" + (i+1) + ": "+result[i]); } }
import java.util.ArrayList; import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); ArrayList<String> list = new ArrayList<String>(); long a,b,c; int i=1; int count = scan.nextInt(); while(count > 0){ a = scan.nextLong(); b = scan.nextLong(); c = scan.nextLong(); if(a+b>c)list.add("true"); else list.add("false"); count --; } /* * case #1: false */ for(String str:list){ System.out.println("Case #"+i+": "+str); i++; } } }提交了多次,错误的原因竟然是因为加了package。
#include<iostream>
using namespace std;
int main(void)
{
int T;
cin >> T;
long int **pt = new long int*[T];
for (int i = 0; i<T; i++)
{
pt[i] = new long int[3];
cin >> pt[i][0] >> pt[i][1] >> pt[i][2];
}
for (int i = 0; i < T; i++)
if (pt[i][0] + pt[i][1] > pt[i][2])
cout << "Case #" << i+1 << ": true" << endl;
else
cout << "Case #" << i+1 << ": false" << endl;
return 0;
}
#include <stdio.h> #include <stdlib.h> int comp(long int a,long int b,long int c) { int r =(a+b)>c?(1):(0); return r; } int main() { int num = 0,i=0; long int a,b,c; scanf("%d",&num); int result[num]; for(i=0;i<num;i++){ scanf("%ld%ld%ld",&a,&b,&c); result[i] = comp(a,b,c); } for(i=0;i<num;i++){ if(result[i]==1) printf("Case #%d: true\n",i+1); else printf("Case #%d: false\n",i+1); } return 0; }
import java.util.*; //简单题 public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int t = in.nextInt(); int i =0; while(t-->0){ i++; long a = in.nextLong(); long b = in.nextLong(); long c = in.nextLong(); System.out.println("Case #"+i+": "+(a+b>c)); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { int p = 0; //System.out.println("Type T that 0 < T <= 10 :"); Scanner _scanner = new Scanner(System.in) ; int T = _scanner.nextInt() ; while (T <= 0 || T > 10) { System.out.println("retype T that 0 < T <= 10 :"); Scanner _scanner1 = new Scanner(System.in) ; T = _scanner1.nextInt() ; } //System.out.println("输入" + T + "组测试用例,每组A B C三个数,并用空格隔开:"); long[][] _2darray = new long[T][3] ; for (int i = 0; i < T; i++) { for (int j = 0; j < 3; j++) { _2darray[i][j] = _scanner.nextLong() ; } } for (int i = 0; i < T; i++) { if (_2darray[i][0] + _2darray[i][1] > _2darray[i][2]) { System.out.println("Case #" + ++p + ": " + "true"); } else { System.out.println("Case #" + ++p + ": " + "false"); } } } }
int
范围是溢出的,说明加数,和均会溢出。所以不能使用int
类型存储输入数据,需要用long long
类型来保证计算不会溢出。 /* * app=PAT-Basic lang=c++ * https://pintia.cn/problem-sets/994805260223102976/problems/994805312417021952 */ #include <cstdio> int main() { int T; long long A, B, C,sum; scanf("%d",&T); for (int i = 0; i < T;i++){ scanf("%lld%lld%lld",&A,&B,&C); sum = A + B; if (sum > C){ printf("Case #%d: true\n",i + 1); } else{ printf("Case #%d: false\n", i + 1); } } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); byte T = in.nextByte(); for (int i = 1; i <= T; i++) System.out.println("Case #" + i + ": " + (in.nextLong() + in.nextLong() > in.nextLong())); } }
#include <bits/stdc++.h> #define il inline int #define re register int //看! #define int long long int n; int A,B,C; signed main(){ scanf("%lld",&n); for(int i=0;i<n;i++){ scanf("%lld %lld %lld",&A,&B,&C); printf("Case #%d: %s\n",i+1,(A+B)>C?"true":"false"); } return 0; }
import java.util.Scanner;