题目传送门

 /*
分情况讨论,在long long范围里可以直接比较
sscanf 直接读到n中去
*/
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <vector>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f; int main(void) //ACdream 1202 Integer in C++
{
//freopen ("G.in", "r", stdin); string s; string s_max = "";
while (cin >> s)
{
long long n;
int len = s.size ();
if (s[] != '-')
{
if (len < )
{
sscanf (s.c_str (), "%lld", &n);
if (n <= ) cout << "short" << endl;
else if (n <= ) cout << "int" << endl;
else cout << "long long" << endl;
}
else if (len == )
{
if (s > s_max) cout << "It is too big!" << endl;
else cout << "long long" << endl;
}
else cout << "It is too big!" << endl;
}
else
{
if (len < )
{
sscanf (s.c_str (), "%lld", &n);
if (n >= -) cout << "short" << endl;
else if (n >= ) cout << "int" << endl;
else cout << "long long" << endl;
}
else if (len == )
{
s.erase (s.begin ());
if (s < s_max) cout << "long long" << endl;
else cout << "It is too big!" << endl;
}
else cout << "It is too big!" << endl;
}
} return ;
} /*
-32768 to 32767
-2147483648 to 2147483647
-9223372036854775808 to 9223372036854775807
short, int, long long
It is too big!
*/
 /*
for循环保存n
注意:2147483647 + 1 -> -2147483648,-2147483648 > 2147483647
在二进制中并不是数学的比大小
*/
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <vector>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f; int main(void) //ACdream 1202 Integer in C++
{
freopen ("G.in", "r", stdin); string s;
char ss[], ss_ll1[] = "", ss_ll2[] = ""; while (scanf ("%s", &ss) == )
{
int len = strlen (ss); long long n;
if (len > ) puts ("It is too big!");
else if (ss[] == '-')
{
if (len == )
{
if (strcmp (ss+, ss_ll1) <= ) puts ("long long");
else puts ("It is too big!");
}
else if (len < )
{
n = ;
for (int i=; i<len; ++i) n = n * + (ss[i] - '');
n = -n;
if (n >= - && n <= ) puts ("short");
else if (n >= - && n <= ) puts ("int");
else puts ("long long");
}
}
else if (len <= )
{
if (len == )
{
if (strcmp (ss, ss_ll2) <= ) puts ("long long");
else puts ("It is too big!");
}
else
{
n = ;
for (int i=; i<len; ++i) n = n * + (ss[i] - '');
if (n >= - && n <= ) puts ("short");
else if (n <= && n >= -) puts ("int");
else puts ("long long");
}
}
else puts ("It is too big!");
} return ;
} /*
-32768 to 32767
-2147483648 to 2147483647
-9223372036854775808 to 9223372036854775807
short, int, long long
It is too big!
*/

判断 ACdream 1202 Integer in C++的更多相关文章

  1. java中Integer,String判断相等与integer的比较大小

    package sfk.bbs.test.springjsbctempletTest; import static org.junit.Assert.*; import org.junit.Test; ...

  2. javascript判断数字是integer还是float

    function isFloat(n) { return n === +n && n !== (n|0); } function isInteger(n) { // 仅能检查32位的数 ...

  3. java 判断 string 转 integer 判断

    NumberUtils.isDigits("1") NumberUtils.isDigits("/") 根据返回 true false 再确定是否转换即可 需要 ...

  4. 判断Integer值相等最好不用==(未整理)

    今天在开发中判断两个Integer值相等, Integer a = 3; Duixiang duixiang = new Duixiang(); duixiang = DAO.getDuixiang( ...

  5. 判断Integer值相等不能用==

    今天在开发中判断两个Integer值相等, Integer a = 3; Duixiang duixiang = new Duixiang(); duixiang = DAO.getDuixiang( ...

  6. Leetcode_8_String to Integer

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41521063 Implement atoi to conv ...

  7. Java 身份证判断性别获取年龄

    import com.alibaba.fastjson.JSON; import org.junit.Test; import java.text.SimpleDateFormat; import j ...

  8. String to Integer (atoi) leetcode java

    题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ca ...

  9. 乘风破浪:LeetCode真题_007_Reverse Integer

    乘风破浪:LeetCode真题_007_Reverse Integer 一.前言 这是一个比较简单的问题了,将整数翻转,主要考察了取整和取余,以及灵活地使用long型变量防止越界的问题. 二.Reve ...

随机推荐

  1. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  2. Ultra-QuickSort

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 44489   Accepted: 16176 ...

  3. Stanford机器学习---第二讲. 多变量线性回归 Linear Regression with multiple variable

    原文:http://blog.csdn.net/abcjennifer/article/details/7700772 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...

  4. 找不到提交和更新按钮,subversion不见了,无法更新和上传代码

    1.查看settings/plugins/下有没有subversion 插件,如果有,确保勾上. 2.VCS->Enable Version Control Integration...

  5. 【Web】关于URL中文乱码问题

    关于URL编码                                        一.问题的由来 URL就是网址,只要上网,就一定会用到.                          ...

  6. iOS tableview 选中Cell后的背景颜色和文字颜色

    做下记录,备忘 改文字颜色其实是UILabel的属性,改背景颜色是cell的属性,都和tableview无关. cell.textLabel.textColor = BAR_COLOR; cell.t ...

  7. Java数据类型中String、Integer、int相互间的转换

    1.Integer转换成int的方法 Integer i;  int k = i.intValue(); 即Integer.intValue(); 2.int转换成Integer int i; Int ...

  8. CKeditor与CKfinder的简单配置

    1.关掉PHP的转义字符,不然从文本框控件中得来的内容,全部有转义字符,不能正常显示,所以在取得文本框控件所传递来的数据之时,要使用下面这样的方式: $内容=stripslashes($_POST[' ...

  9. HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)

    Fibonacci again and again Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & ...

  10. VS添加lib库

    #pragma comment(lib,"opengl32.lib")