python x 0b1011_PAT 1011 A+B和C (15)(C++JAVAPython)
1011?A+B和C (15)(15?分)
給定區(qū)間[-2^31^, 2^31^]內(nèi)的3個(gè)整數(shù)A、B和C,請(qǐng)判斷A+B是否大于C。
輸入格式:
輸入第1行給出正整數(shù)T(<=10),是測(cè)試用例的個(gè)數(shù)。隨后給出T組測(cè)試用例,每組占一行,順序給出A、B和C。整數(shù)間以空格分隔。
輸出格式:
對(duì)每組測(cè)試用例,在一行中輸出“Case #X: true”如果A+B>C,否則輸出“Case #X: false”,其中X是測(cè)試用例的編號(hào)(從1開(kāi)始)。
輸入樣例:
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
注意:數(shù)據(jù)用long long(測(cè)試點(diǎn)2、3答案錯(cuò)誤)
C++:
#include
using namespace std;
int main() {
int n;
long long a, b, c; //注意數(shù)據(jù)范圍
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")
總結(jié)
以上是生活随笔為你收集整理的python x 0b1011_PAT 1011 A+B和C (15)(C++JAVAPython)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql core 文件_MySQL未
- 下一篇: 中山行书百年纪念版字体可以商用吗_干货|