A+B和C (15)

4 篇文章 0 订阅

给定区间[-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开始)。
示例1
输入
4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647
输出
情况1:错误
情况2:正确
情况3:正确
情况4:错误

using System;

namespace PAT
{
    class Program
    {
        static void Main(string[] args)
        {
            int NumCount = int.Parse(Console.ReadLine());
            string[] nums = new string[NumCount];
            string[] result=new string[NumCount];
            for (int i = 0; i < nums.Length; i++)
            {
                nums[i] = Console.ReadLine();
                string[] a = nums[i].Split(' ');
                if (long.Parse(a[0])+long.Parse(a[1])>long.Parse(a[2]))
                {
                    result[i] = $"Case #{i+1}: true";
                }
                else
                {
                    result[i] = $"Case #{i+1}: false";
                }
            }

            for (int i = 0; i < result.Length; i++)
            {
                Console.WriteLine(result[i]);
            }

            Console.ReadKey();







            //不再使用自己写的分割方法,头疼
            //string a = "dasdsafasf fasfsafergfargag gagasasg";
            //string[] ss=a.Split(' ');
            //for (int i = 0; i < ss.Length; i++)
            //{
            //    Console.WriteLine(ss[i]);
            //}

            //Console.ReadKey();


        } 
    }
}

这道题最关键的是使用int会溢出,所以使用long

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值