[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
给定区间 [−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
【思路】
①我是按照题目给的输入格式做的,我看其他的博客主大部分是这样的:每输入一行就进行判断然后输出,奇怪的是通过了测试。
②由于 3 个整数已经给定区间 [−2^31,2^31]
,这点得小心,一般的int(2^31-1)是不能满足的,long(2^31-1)也是不行的。只能选择long long (2^63-1)
足够了。但是测试时,发现用int 有一个测试点过不去,用long的话没有问题。感觉此题不严谨。
③我是先把输入进来的所有数据先保存到一个一维数组里面,然后再根据输出格式进行打印、数据处理。
另附上测试代码:
#include <stdio.h> int main() { printf("short 占%d个字节\n",sizeof(short));
printf("int 占%d个字节\n",sizeof(int)); printf("long 占%d个字节\n",sizeof(long));
printf("long long 占%d个字节\n\n\n",sizeof(long long)); printf("unsigned short
占%d个字节\n",sizeof(unsigned short)); printf("unsigned int
占%d个字节\n",sizeof(unsigned int)); printf("unsigned long
占%d个字节\n",sizeof(unsigned long)); printf("unsigned long
long占%d个字节\n",sizeof(unsigned long long)); return 0; }
【参考代码】
#include <stdio.h> int main() { int n;/需要测试的行数 long
array[30];//每行数据都保存在这数组里,30=每行有3个整数*10行 int i=0,j=0;//j是用来打印行号的 char
ch;//保存空格和换行用的 scanf("%d",&n); for(i=0;i<3*n;) { do {
scanf("%lld",&array[i++]); ch=getchar(); } while(ch!='\n'); }//数据输入完毕
for(i=0;i<=(3*n-3);i+=3)//数据处理 { printf("Case #%d: ",(++j));//j是用来打印行号的
if((array[i]+array[i+1])>(array[i+2])) printf("true\n"); else
printf("false\n"); } return 0; }