给定区间[-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