首页 > 试题广场 >

A+B和C (15)

[编程题]A+B和C (15)
  • 热度指数:159834 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
给定区间[-231, 231]内的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开始)。
示例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
推荐
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");
                }
            }    
    }

}
一把辛酸泪T_T,没做过OJ的记得java类名为Main,此题大家记得测试的数据定义为long类型,case首字母大写,要与题干要求一致,无力吐槽。。。。
编辑于 2015-06-19 17:40:10 回复(44)
k = 0
n = int(input())
for i in range(n):
    n = input().split()
    s = list(n)
    if len(s) == 3:
        k+=1
        if int(s[0])+int(s[1])>int(s[2]):
            print("Case #%d: true"%k)
        else:
            print("Case #%d: false"%k)



发表于 2021-01-11 00:49:37 回复(0)
n = eval(input())
for i in range(n):
    a, b, c = [eval(i) for i in input().split()]
    print('Case #{}: '.format(i + 1), end = '')
    print('true') if  a + b > c else print('false')

发表于 2019-08-19 22:29:54 回复(0)
n=int(input())
fori in range(n):
    num=list(input().split(' '))
    if int(num[0])+int(num[1])>int(num[2]):
        print("Case #{0}:{1}".format(i+1,' true'))
    else:
        print("Case #{0}:{1}".format(i+1,' false'))
#python虽然是解释型语言,但真的很简单
发表于 2019-05-27 21:43:59 回复(0)
a=int(input())
for i in range(a):
    b,c,d=map(int,input().split())
    print("Case #"+str(i+1)+": true" if b+c>d else "Case #"+str(i+1)+": false")

发表于 2019-03-26 10:17:17 回复(0)

def compareABC(a,b,c,n):
    if a+b>c:
        print("Case #%d: true"%(n));
    else:
        print("Case #%d: false"%(n));

n=int(input());
mtr = [[0 for i in range(3)] for i in range(n)];
for i in range(n):
    mtr[i]=[int(n) for n in input().split(" ")];
for j in range(n):
    compareABC(mtr[j][0],mtr[j][1],mtr[j][2],j+1);
Pyhton版,想了一会!
发表于 2019-03-01 11:03:27 回复(0)
num=input()
for i in num:
    print("Case #",i,": ",input()+input()>input())

运行结果:
测试用例:
3
1 2 3
2 3 4
2147483647 0 2147483646

对应输出应该为:

Case #1: false
Case #2: true
Case #3: true

你的输出为:

Case # 3 :  False

本地测试没有错啊,大神帮忙看看那
发表于 2019-02-02 10:23:07 回复(0)
T=input("正整数T(<=10)")
T=int(T)
for i in range(T):
    a,b,c=input("顺序给出A、B和C").split()
    a=int(a)
    b=int(b)
    c=int(c)
    if a+b>c:
        print("Case #%d: true"%(i+1))
    else:
        print("Case #%d: false"%(i+1))

求助啊 一直找不到问题出在哪里
发表于 2018-08-23 16:03:56 回复(0)
n = input()
array = [] for i in range(n):
    a, b, c = raw_input().split(" ")
    array.append([int(a), int(b), int(c)]) for i in range(n):
    flag = "true"   for a in array[i]: if a >= 2**31 and a <= -2**31:
            flag = "false"   if array[i][0] + array[i][1] <= array[i][2]:
        flag = "false"   print "Case #" + str(i + 1) + ": " + flag
发表于 2018-03-08 09:34:22 回复(0)
n=int(raw_input())
input_list=[]
for i in range(n):
    input_list.append(map(int,raw_input().split(' ')))
for i in range(n):
    if input_list[i][0]+input_list[i][1]>input_list[i][2]:
        print 'Case #%s: true'%(i+1)
    else:
        print 'Case #%s: false'%(i+1)

发表于 2018-01-04 17:47:59 回复(0)
a=input()
a=int(a)
data=[]
while int(a)>0 :
    data.append(input().split(' '))
    a-=1
j=1
for x in data:
    if (int(x[0])+int(x[1]))>int(x[2]):
        print("Case #%d: true" % j)
    else:
        print("Case #%d: false" % j) 
    j+=1

发表于 2017-11-19 21:31:52 回复(0)

也不知道为什么在PyCharm里总是读不到最后一行,但运行能AC

T = input()
for i in xrange (T):
    a,b,c = raw_input().split()
    if int(a) + int(b) > int(c):
        print "Case #" + str(i + 1) + ": true"
    else :
        print "Case #" + str(i + 1) + ": false"
编辑于 2017-11-03 12:46:31 回复(0)

python 4行解法:

a=int(input())
for i in range(a):
    b,c,d=map(int,input().split())
    print("Case #"+str(i+1)+": true" if b+c>d else "Case #"+str(i+1)+": false")
发表于 2017-10-09 11:17:42 回复(8)
t = int(input())
num = []
for i in range(t):
    num.append(input().split())
n = 1
for i in num:
    if int(i[0])+int(i[1]) > int(i[2]):
        print('Case #'+str(n)+': true')
    else:
        print('Case #'+str(n)+': false')
    n += 1
发表于 2017-09-28 18:48:33 回复(0)
# encoding: utf-8
​# 直接作为循环次数
​for i in range(int(raw_input())):
    # 接下来每行读取三个数, 用map转换为int
​    a, b, c = map(int, raw_input().strip().split())  
    print('Case #%s: %s' % (i + 1, 'true' if a > c - b else 'false))
编辑于 2017-02-19 15:01:01 回复(0)
count = int(raw_input())
for i in range(count):
    nums = raw_input()
    n = nums.split()
    if int(n[0]) + int(n[1]) > int(n[2]):
        print 'Case #%d:' % (i+1), 'true'
    else:
        print 'Case #%d:' % (i+1), 'false'
人生苦短,我用Python
发表于 2016-11-03 16:10:46 回复(0)
count = int(raw_input())
for i in range(count):
    nums = raw_input()
    n = nums.split()
    if int(n[0]) + int(n[1]) > int(n[2]):
        print 'Case #%d:' % (i+1), 'true'
    else:
        print 'Case #%d:' % (i+1), 'false'
人生苦短,我用Python
发表于 2016-10-25 22:54:28 回复(0)
import sys 
i=0
all=[]
for line in sys.stdin:
    if i==0:
        n=int(line.strip())
        i=i+1
    else:
        all.append(line.strip().split())
for i in range(n):
    if float(all[i][0])+float(all[i][1])>float(all[i][2]):
print "Case #%i: true"%(i+1)   
    else:
print "Case #%i: false"%(i+1)
发表于 2016-07-31 01:13:14 回复(1)

问题信息

难度:
20条回答 90666浏览

热门推荐

通过挑战的用户

A+B和C (15)