试题01 A+B和C
来源:互联网 发布:知之一字 众妙之门 编辑:程序博客网 时间:2024/06/10 20:20
要求:时间限制 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开始)。
示例:
输入:
41 2 32 3 42147483647 0 21474836460 -2147483648 -2147483647
输出:
Case #1: falseCase #2: trueCase #3: trueCase #4: false解析:本题主要注意考虑A+B溢出的问题答案示例:1.#include <iostream>#define N 10using namespace std; int main(){ int count(0), A[N], B[N], C[N]; cin >> count; for (int i = 0; i != count; ++i) { cin >> A[i] >> B[i] >> C[i]; } for (int i = 0; i != count; ++i) { (A[i] > C[i] - B[i]) ? cout << "Case #" << i + 1 << ": true\n" :cout << "Case #" << i + 1 << ": false\n"; } return 0;}
2.#include
"iostream"
using namespace std;
int
main()
{
int
numberT;
cin>>numberT;
long
int
number[numberT][
3
];
for
(
int
j=
0
;j<numberT;j++)
{
for
(
int
i=
0
;i<
3
;i++)
{
cin>>number[j][i];
}
}
for
(
int
j =
0
; j < numberT; j++)
{
number[j][
0
] + number[j][
1
] <= number[j][
2
] ?
cout<<
"Case #"
<<j+
1
<<
": false\n"
:cout<<
"Case #"
<<j+
1
<<
": true\n"
;
}
return
0
;
3.}
import
java.util.Scanner;
public
class
Main {
public
static
void
main(String[] args) {
Scanner sc =
new
Scanner(System.in);
int
i=
0
;
int
num=
0
;
long
a,b,c;
a=
0
;b=
0
;c=
0
;
num=sc.nextInt();
while
(i++<num){
a=sc.nextLong();
b=sc.nextLong();
c=sc.nextLong();
if
((a+b)>c){
System.out.println(
"Case #"
+i+
":"
+
" true"
);
}
else
{
System.out.println(
"Case #"
+i+
":"
+
" false"
);
}
}
}
4.}
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++;
}
}
}
0 0
- 试题01 A+B和C
- (a^b)%c和(a/b)%c
- A+B和C
- A+B和C
- A+B和C
- A+B和C
- A+B和C
- A+B和C
- PAT1011. A+B和C
- 1011 A+B和C
- 1011. A+B和C
- A+B和C (15)
- 1011. A+B和C
- 1011. A+B和C
- 1011 A+B和C
- PAT1011. A+B和C
- 1011.A+B和C
- 1011. A+B和C
- 不使用quartz实现定时,使用@Scheduled注解实现定时--一次配置到处使用
- Nutz中过滤特殊字符
- nginx 或tengine 访问日志分割处理
- ios uiwindow 的用法
- Node Eviction due to OLOGGERD High CPU
- 试题01 A+B和C
- ios 9 隐藏 StatusBar
- 下拉放大headView
- 四道Java基础题 你能对几道?
- 常用sqlite的命令收集贴
- Qt之界面实现技巧
- [leetcode] 40. Combination Sum II 解题报告
- Imagemagic的安装
- C++ STL 容器总结