试题01 A+B和C

        要求:时间限制 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
	解析:本题主要注意考虑A+B溢出的问题
	答案示例:
	1.
#include <iostream>
#define N 10
using 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值