B1011 & 问题 F: A+B和C (15)

本文介绍了一个算法,用于判断三个给定整数A、B和C在[-2^31,2^31]区间内,A+B是否大于C。通过使用long long类型变量避免整数溢出,确保了算法的正确性。文章还回顾了不同整型变量的取值范围,包括short、long、int和long long。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

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

顺便复习一下整型(不含无符号)范围...

shor:[-2^15,2^15-1]  大于10^4 小于10^5

long和int相当:[-2^31 , 2^31 -1]  大于10^9   小于10^10

QAQ 一直以为long的范围介于int 和 longlong?比如47次方啥的

long long 相当于__int64 (VC) :[-2^63,2^63-1]  大于10^18 小于10^19

 

#include<cstdio>
int main()
{	
	int T;
	scanf("%d",&T);
	for(int i=1;i<=T;i++) 
	{
		long long A,B,C;
		scanf("%lld%lld%lld",&A,&B,&C);
		if(A+B>C)
			printf("Case #%d: true\n",i);
		else
			printf("Case #%d: false\n",i);
	}
	return 0;
}

格式错误有点尴尬...:和true之间有个空格...

为这段代码加注释module sy2(a,b,c,d,e,f,g,sel,clk,en); output a,b,c,d,e,f,g; output [7:0]sel; input [7:0] en; input clk; reg a,b,c,d,e,f,g; reg [7:0] sel; reg clk_reg; reg [8:0] count; reg [2:0] state; parameter s0=3&#39;d0,s1=3&#39;d1,s2=3&#39;d2,s3=3&#39;d3, s4=3&#39;d4,s5=3&#39;d5,s6=3&#39;d6,s7=3&#39;d7; always@(posedge clk) if(count==9&#39;d400) begin clk_reg&lt;=~clk_reg; count&lt;=9&#39;d0; end else count&lt;=count+9&#39;d1; always@(posedge clk_reg) begin case(state) s0: begin if(en[7]) begin sel&lt;=8&#39;b0111_1111; {a,b,c,d,e,f,g}&lt;=7&#39;b1101101; end else sel&lt;=8&#39;b1111_1111; state&lt;=s1; end s1: begin if(en[6]) begin sel&lt;=8&#39;b1011_1111; {a,b,c,d,e,f,g}&lt;=7&#39;b1111110; end else sel&lt;=8&#39;b1111_1111; state&lt;=s2; end s2: begin if(en[5]) begin sel&lt;=8&#39;b1101_1111; {a,b,c,d,e,f,g}&lt;=7&#39;b1111110; end else sel&lt;=8&#39;b1111_1111; state&lt;=s3; end s3: begin if(en[4]) begin sel&lt;=8&#39;b1110_1111; {a,b,c,d,e,f,g}&lt;=7&#39;b1101101; end else sel&lt;=8&#39;b1111_1111; state&lt;=s4; end s4: begin if(en[3]) begin sel&lt;=8&#39;b1111_0111; {a,b,c,d,e,f,g}&lt;=7&#39;b1111110; end else sel&lt;=8&#39;b1111_1111; state&lt;=s5; end s5: begin if(en[2]) begin sel&lt;=8&#39;b1111_1011; {a,b,c,d,e,f,g}&lt;=7&#39;b1101101; end else sel&lt;=8&#39;b1111_1111; state&lt;=s6; end s6: begin if(en[1]) begin sel&lt;=8&#39;b1111_1101; {a,b,c,d,e,f,g}&lt;=7&#39;b1111110; end else sel&lt;=8&#39;b1111_1111; state&lt;=s7; end s7: begin if(en[0]) begin sel&lt;=8&#39;b1111_1110; {a,b,c,d,e,f,g}&lt;=7&#39;b1111001; end else sel&lt;=8&#39;b1111_1111; state&lt;=s0; end default:state&lt;=s0; endcase end endmodule
05-31
module fq_cepin(fx,f2,f0,select,q); input fx,f0,f2,select; output [31:0] q; reg [31:0] cnt1; reg [31:0] fq; reg f1; always@(negedge f0) f1&lt;=!f1; always@(posedge fx) if(!f1) cnt1&lt;=32&#39;d0; else if(cnt1[27:0]==28&#39;h9999999) begin cnt1[31:28]&lt;=cnt1[31:28]+1&#39;b1; cnt1[27:0]&lt;=28&#39;h0000000; end else if(cnt1[23:0]==24&#39;h999999) begin cnt1[27:24]&lt;=cnt1[27:24]+1&#39;b1; cnt1[23:0]&lt;=24&#39;h000000; end else if(cnt1[19:0]==20&#39;h99999) begin cnt1[23:20]&lt;=cnt1[23:20]+1&#39;b1; cnt1[19:0]&lt;=20&#39;h00000; end else if(cnt1[15:0]==16&#39;h9999) begin cnt1[19:16]&lt;=cnt1[19:16]+1&#39;b1; cnt1[15:0]&lt;=16&#39;h0000; end else if(cnt1[11:0]==12&#39;h999) begin cnt1[15:12]&lt;=cnt1[15:12]+1&#39;b1; cnt1[11:0]&lt;=12&#39;h000; end else if(cnt1[7:0]==8&#39;h99) begin cnt1[11:8]&lt;=cnt1[11:8]+1&#39;b1; cnt1[7:0]&lt;=8&#39;h00; end else if(cnt1[3:0]==4&#39;h9) begin cnt1[7:4]&lt;=cnt1[7:4]+1&#39;b1; cnt1[3:0]&lt;=4&#39;h0; end else cnt1[3:0]&lt;=cnt1[3:0]+1&#39;b1; always@(negedge f1) fq&lt;=cnt1; reg[25:0] n1,n2,p1,p2; always@(posedge f2) if(!fx) n1&lt;=26&#39;d0; else n1&lt;=n1+1&#39;b1; always@(negedge fx) p1&lt;=n1; always@(posedge f2) if(fx) n2&lt;=26&#39;d0; else n2&lt;=n2+1&#39;b1; always@(posedge fx) p2&lt;=n2; reg[7:0] duty; always@(posedge f1) if(p1&gt;26&#39;d0 ) if(p2&gt;26&#39;d0) duty&lt;=(p1*10)/(p1+p2)*16+((p1*100)/(p1+p2))%10; assign q=(select)?{24&#39;d0,duty}:fq; endmodule 这段代码在EDA箱子数码管出来的箱子结果是什么
最新发布
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云无心鸟知还

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值