Petya and Java
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d& %I64u
SubmitStatus
Description
Little Petya has recently started attending a programming club. Naturallyhe is facing the problem of choosing a programming language. After longconsiderations he realized that Java is the best choice. The main argument infavor of choosing Java was that it has a very large integer data type, calledBigInteger.
But having attended several classes of the club, Petya realized that notall tasks require using the BigInteger type. It turned out that in some tasksit is much easier to use small data types. That's why a question arises:"Which integer type to use if one wants to store a positive integer n?"
Petya knows only 5 integer types:
1) byte occupies 1 byte and allows you to store numbers from - 128 to 127
2) short occupies 2 bytes and allows you to store numbers from - 32768 to 32767
3) int occupies 4 bytes and allows you to store numbers from - 2147483648 to2147483647
4) long occupies 8 bytes and allows you to store numbers from - 9223372036854775808to 9223372036854775807
5) BigInteger can store any integer number, but at that it is not aprimitive type, and operations with it are much slower.
For all the types given above the boundary values are included in thevalue range.
From this list, Petya wants to choose the smallest type that can store apositive integern. Since BigInteger works much slower, Peter regards itlast. Help him.
Input
The first line contains a positive numbern. It consists of no morethan 100 digits and doesn't contain any leading zeros. The numberncan't be represented as an empty string.
Please, do not use %lld specificator to read or write 64-bit integers inC++. It is preffered to use cout (also you may use %I64d).
Output
Print the first type from the list "byte, short, int, long,BigInteger", that can store the natural numbern, in accordancewith the data given above.
Sample Input
Input
127
Output
byte
Input
130
Output
short
Input
123456789101112131415161718192021222324
Output
BigInteger
题目分析:
输入一个正整数,判别它的字节类型。
解题思路:
因为输入正数太大,所以采用字符串来存储整数,再利用字符串中strcmp函数来让输入整数与每种类型的最大值比较。
核心代码:
if(l<3||l==3&&strcmp(c,"127")<=0)
printf("byte\n");
else
if(l<5||l==5&&strcmp(c,"32767")<=0)
printf("short\n");
else
if(l<10||l==10&&strcmp(c,"2147483647")<=0)
printf("int\n");
else
if(l<19||l==19&&strcmp(c,"9223372036854775807")<=0)
printf("long\n");
else
printf("BigInteger\n");