42. 简单的求和

君莫寒

include

include

define INT_MAX 2147483647

int sum(int a, int b)
{
int c;
c=INT_MAX-a;
if(b>c)
return-1;
else
return a+b;
}

int main() {
int a, b;
scanf(“%d%d”, &a, &b);
printf(“%d\n”, sum(a, b));
return 0;
}

mydream-smc

本人测试代码,第四个数据应该是1000000000,第七个数据超过最大范围了

include

//* Specification of Mean *
long long sum(long long a, long long b) {

long long c;
c=a+b;

if(c>1000000000) return -1;
return c;

}

/*********/
int main() {
long long a, b;
scanf(“%lld%lld”, &a, &b);
printf(“%lld\n”, sum(a, b));
return 0;
}

mydream-smc

标准代码

include

int main(){
int a,b;
scanf(“%d%d”,&a,&b);
if(a+b<0)
printf(“-1”);
else
printf(“%d”,a+b);
}

你当前正在回复 博客/题目
存在问题!