Description Little Petya has recently started attending a programming club.Naturally he is facing the problem of choosing a programminglanguage. After long considerations he realized that Java is thebest choice. The main argument in favor of choosing Java was thatit has a very large integer data type, called BigInteger. But having attended several classes of the club, Petya realizedthat not all tasks require using the BigInteger type. It turned outthat in some tasks it is much easier to use small data types.That's why a question arises: "Which integer type to use if onewants to store a positive integer Petya knows only 5 integer types: 1) 2) 3) 4) 5) For all the types given above the boundary values are includedin the value range. From this list, Petya wants to choose the smallest type that canstore a positive integer Input The first line contains a positivenumber Please, do not use Output Print the first type from the list "byte, Sample Input
Input
127
Output
byte
Input
130
Output
short
Input
123456789101112131415161
Output
BigInteger |
以前没真正弄明白函数strcmp的具体用途,以为只能比较字符,原来比较字符就是比较ASCLL码,!!也就是可以比较数字大小(当然是在位数同样的前提下),这样的话,先判断
位数在进行比较,这题就AC了!
#include<iostream> using namespace std; int main() { int l; char c[105]; while(scanf("%s",c)!=EOF) { l=strlen(c); if(l<3||l==3&&strcmp(c,"127")<=0) cout<<"byte"<<endl; else if(l<5||l==5&&strcmp(c,"32767")<=0) cout<<"short"<<endl; else if(l<10||l==10&&strcmp(c,"2147483647")<=0) cout<<"int"<<endl; else if(l<19||l==19&&strcmp(c,"9223372036854775807")<=0) cout<<"long"<<endl; else cout<<"BigInteger"<<endl; } return 0; }
1万+




被折叠的 条评论
为什么被折叠?



