博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
判断 ACdream 1202 Integer in C++
阅读量:6212 次
发布时间:2019-06-21

本文共 3110 字,大约阅读时间需要 10 分钟。

 

1 /* 2     分情况讨论,在long long范围里可以直接比较 3     sscanf 直接读到n中去 4 */ 5 #include 
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 using namespace std;14 15 const int MAXN = 1e4 + 10;16 const int INF = 0x3f3f3f3f;17 18 int main(void) //ACdream 1202 Integer in C++19 {20 //freopen ("G.in", "r", stdin);21 22 string s; string s_max = "9223372036854775807";23 while (cin >> s)24 {25 long long n;26 int len = s.size ();27 if (s[0] != '-')28 {29 if (len < 19)30 { 31 sscanf (s.c_str (), "%lld", &n);32 if (n <= 32767) cout << "short" << endl;33 else if (n <= 2147483647) cout << "int" << endl;34 else cout << "long long" << endl;35 }36 else if (len == 19)37 {38 if (s > s_max) cout << "It is too big!" << endl;39 else cout << "long long" << endl;40 }41 else cout << "It is too big!" << endl;42 }43 else44 {45 if (len < 20)46 {47 sscanf (s.c_str (), "%lld", &n);48 if (n >= -32768) cout << "short" << endl;49 else if (n >= 2147483647) cout << "int" << endl;50 else cout << "long long" << endl;51 }52 else if (len == 20)53 {54 s.erase (s.begin ());55 if (s < s_max) cout << "long long" << endl;56 else cout << "It is too big!" << endl;57 }58 else cout << "It is too big!" << endl;59 }60 }61 62 return 0;63 }64 65 /*66 -32768 to 3276767 -2147483648 to 214748364768 -9223372036854775808 to 922337203685477580769 short, int, long long70 It is too big!71 */
1 /* 2     for循环保存n 3     注意:2147483647 + 1 -> -2147483648,-2147483648 > 2147483647 4         在二进制中并不是数学的比大小 5 */ 6 #include 
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 16 const int MAXN = 1e4 + 10;17 const int INF = 0x3f3f3f3f;18 19 int main(void) //ACdream 1202 Integer in C++20 {21 freopen ("G.in", "r", stdin);22 23 string s;24 char ss[33], ss_ll1[] = "9223372036854775808", ss_ll2[] = "9223372036854775807";25 26 while (scanf ("%s", &ss) == 1)27 {28 int len = strlen (ss); long long n;29 if (len > 20) puts ("It is too big!");30 else if (ss[0] == '-')31 {32 if (len == 20)33 {34 if (strcmp (ss+1, ss_ll1) <= 0) puts ("long long");35 else puts ("It is too big!");36 }37 else if (len < 20)38 {39 n = 0;40 for (int i=1; i
= -32768 && n <= 32767) puts ("short");43 else if (n >= -2147483648 && n <= 2147483647) puts ("int");44 else puts ("long long");45 }46 }47 else if (len <= 19)48 {49 if (len == 19)50 {51 if (strcmp (ss, ss_ll2) <= 0) puts ("long long");52 else puts ("It is too big!");53 }54 else55 {56 n = 0;57 for (int i=0; i
= -32768 && n <= 32767) puts ("short");59 else if (n <= 2147483647 && n >= -2147483648) puts ("int");60 else puts ("long long");61 }62 }63 else puts ("It is too big!");64 }65 66 return 0;67 }68 69 /*70 -32768 to 3276771 -2147483648 to 214748364772 -9223372036854775808 to 922337203685477580773 short, int, long long74 It is too big!75 */

 

转载于:https://www.cnblogs.com/Running-Time/p/4415733.html

你可能感兴趣的文章
新maven项目创建JSP出现小红叉报错 javax.servlet.http.HttpServlet not found
查看>>
微信小程序列表加载更多
查看>>
leetcode笔记-1 twosum
查看>>
深浅拷贝
查看>>
sql查询重复记录、删除重复记录方法大全
查看>>
odoo开发笔记 -- 用户配置界面增加模块访问权限
查看>>
instanceof函数内部机制探析
查看>>
linux下phpstorm的快速安装
查看>>
批量删除和批量修改(参数使用list)
查看>>
前端通用框架可行性研究报告之弹窗
查看>>
数据转换
查看>>
IOS在一个程序中启动另一个程序
查看>>
Dubbo初探
查看>>
CDI Features
查看>>
Linux中安装Oracle jdk
查看>>
MFC界面伸缩
查看>>
笔记本搜不到路由无线信号
查看>>
动态规划算法学习总结
查看>>
java 24小时倒计时案例
查看>>
Memcached
查看>>