今天第一次上交ACM的题目,从简单的A+B开始,题目简单的不能再简单了,所以就尝试找了一下得到int最大值的方法以及得到系统的位数:
Description:
Calculate a+b
Input:
Two integer a,b (0<=a,b<=10)
Output:
Output a+b
Sample Input:
1 2
Sample Output:
3
链接:(A+B)[http://poj.org/problem?id=1000]
解决代码:
#include<stdio.h>
#include<math.h>
// get system's bit, maybe right ?
int getSysBit() {
int a = 111;
long b = 3333;
int c = sizeof(b);
if(c == 8) {
return 64;
} else {
return 32;
}
}
int main() {
int a=0,b=0;
scanf("%d %d",&a,&b);
// this method could alse get the max and min
int e = getSysBit();
int max = ~(unsigned int)0 / 2;
int min = -(int)(~(unsigned int)0 / 2)-1;
if(min < a && a < max && min < b && b <max) {
printf("%d\n",a+b);
} else {
printf("please input value between %d,%d \n%d,%d\n",min,max,a,b);
}
return 0;
}
网友评论