acm 2016/5/18 hpu15级练习 A
来源:互联网 发布:成都知美术馆开放时间 编辑:程序博客网 时间:2024/05/18 03:48
Description
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.
But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it 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 to 2147483647
4) long occupies 8 bytes and allows you to store numbers from - 9223372036854775808 to 9223372036854775807
5) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.
For all the types given above the boundary values are included in the value range.
From this list, Petya wants to choose the smallest type that can store a positive integer n. Since BigInteger works much slower, Peter regards it last. Help him.
Input
The first line contains a positive number n. It consists of no more than 100 digits and doesn't contain any leading zeros. The number ncan't be represented as an empty string.
Please, do not use %lld specificator to read or write 64-bit integers in C++. 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 number n, in accordance with the data given above.
Sample Input
127
byte
130
short
123456789101112131415161718192021222324
题意:给一个数据(很长),判断它的数据类型。
做了这题才知道自己以前对strcmp函数并没有真正理解!
strcmp:用于字符串的比较,从左到右,知道遇到不同字符或'\0'停止。例如:abcd b 则b大,abcd acdef 则abcd大。
所以题中比较不同长度字符串时,用len 记录长度直接比较即可,然后相同长度用strcmp 比较。
#include <cstdio>#include <cstring>int main(){char str[110];int len;while(~scanf("%s",str)){len=strlen(str);if(len<3||(len==3&&strcmp(str,"127")<=0))printf("byte\n");else if(len<5||(len==5&&strcmp(str,"32767")<=0))printf("short\n");else if(len<10||(len==10&&strcmp(str,"2147483647")<=0))printf("int\n");else if(len<19||(len==19&&strcmp(str,"9223372036854775807")<=0))printf("long\n");else printf("BigInteger\n");}return 0;}
- acm 2016/5/18 hpu15级练习 A
- acm 2016/5/18 hpu15级练习 B
- acm 2016/5/18 hpu15级练习 C
- acm 2016/5/18 hpu15级练习 G
- acm 2016/5/18 hpu15级练习 J
- HPU15级练习(一)并查集 :A - Ubiquitous Religions
- HPU15级练习(一)并查集 :C - The Suspects
- HPU15级练习(一)并查集 :B - Wireless Network
- ACM练习 A Mathematical Curiosity
- ACM 1000A+B Problem 练习
- ACM俱乐部练习-A+B without carry
- ACM第一次练习—1000A
- ACM递归递推练习 Problem A
- ACM俱乐部练习--A+B 输入输出练习I
- ACM俱乐部练习-A+B 输入输出练习II
- ACM俱乐部练习-A+B 输入输出练习III
- ACM俱乐部练习-A+B 输入输出练习IV
- ACM俱乐部练习- A+B 输入输出练习V
- java中必须了解的常用类
- 常见排序之---希尔排序
- Mysql复习秘籍(燕十八出品)
- 关于sql语句的inner join,left join ,right join的区别
- Codeforces Round #353 (Div. 2) E. Trains and Statistic(求d[i][j]的和的最小值(1<=i<=n,i+1<=j<=n))
- acm 2016/5/18 hpu15级练习 A
- java并行排序测试——并行归并、并行快排
- 第一阶段总结
- 阶段总结
- 环信libHyphenateSDK.a和支付宝libcrypto.a冲突问题解决办法
- Android消息机制(读书笔记)
- c3p0检测并发访问连接
- VS2008 和 MatlabR2015a 混合编程
- POJ3630WA