题目传送门

 /*
分情况讨论,在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. MySQL之aborted connections和aborted clients

    影响Aborted_clients 值的可能是客户端连接异常关闭,或wait_timeout值过小. 最近线上遇到一个问题,接口日志发现有很多超时报错,根据日志定位到数据库实例之后发现一切正常,一般来 ...

  2. IIS假死状态处理

    为应用程序池 'DefaultAppPool' 提供服务的进程关闭时间超过了限制  服务器经常产生“应用程序池 'DefaultAppPool' 提供服务的进程关闭时间超过了限制.进程 ID 是 '2 ...

  3. [codeforces 528]A. Glass Carving

    [codeforces 528]A. Glass Carving 试题描述 Leonid wants to become a glass carver (the person who creates ...

  4. PCL初步使用

    转载:http://blog.csdn.net/vbskj/article/details/7819828 本次试验的目的是利用PCL库来重建地形点云数据,并进行显示.总体流程是1)把DEM数据导入P ...

  5. php用soap创建webservice

    php提供了一个专门用于soap操作的扩展库,使用该扩展库后 可以直接在php中进行soap操作.下面将介绍soap的基本操作. 一.soap扩展的使用方法 php的soap扩展库通过soap协议实现 ...

  6. poj3026(bfs+prim)

    The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. ...

  7. 如何使用setup.py文件

    setup.py文件的使用:% python setup.py build #编译% python setup.py install    #安装% python setup.py sdist     ...

  8. Python网络编程(4)——异步编程select & epoll

    在SocketServer模块的学习中,我们了解了多线程和多进程简单Server的实现,使用多线程.多进程技术的服务端为每一个新的client连接创建一个新的进/线程,当client数量较多时,这种技 ...

  9. 8.python笔记之面向对象基础

    title: 8.Python笔记之面向对象基础 date: 2016-02-21 15:10:35 tags: Python categories: Python --- 面向对象思维导图 (来自1 ...

  10. 【python】队列

    来源:http://www.cnblogs.com/yupeng/p/3413852.html 关于队列 >>> from collections import deque > ...