ACM---A+B-1000

今天第一次上交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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容