python x 0b1011_PAT 1011 A+B和C (15)(C++JAVAPython)
1011?A+B和C (15)(15?分)
給定區(qū)間[-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
注意:數據用long long(測試點2、3答案錯誤)
C++:
#include
using namespace std;
int main() {
int n;
long long a, b, c; //注意數據范圍
cin >> n;
int k = 1;
while (n--) {
cin >> a >> b >> c;
switch (a + b > c){
case 1:
cout << "Case #" << k++ << ": true"<
break;
case 0:
cout << "Case #" << k++ << ": false"<
break;
}
}
return 0;
}
JAVA:
import java.util.Scanner;
public class Main{
public static boolean judge(long A,long B,long C){
return A+B>C;
}
public static void main(String [] args){
Scanner input=new Scanner(System.in);
long A,B,C;
int n=input.nextInt();
for(int i=1;i<=n;i++){
A=input.nextLong();
B=input.nextLong();
C=input.nextLong();
System.out.print("Case #"+i+": ");
if(judge(A,B,C))
System.out.println("true");
else
System.out.println("false");
}
}
}
Python:
if __name__=="__main__":
n=int(input())
for i in range(0,n):
a,b,c=map(int,input().split())
print("Case #%d: " % (i+1),end="")
if a+b>c:
print("true")
else:
print("false")
總結
以上是生活随笔為你收集整理的python x 0b1011_PAT 1011 A+B和C (15)(C++JAVAPython)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql core 文件_MySQL未
- 下一篇: 中山行书百年纪念版字体可以商用吗_干货|