题目传送门

 /*
分情况讨论,在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. Song Jiang's rank list

     Song Jiang's rank list Time Limit:1000MS     Memory Limit:512000KB     64bit IO Format:%I64d & ...

  2. js打印(控件)及多种方式

    非常好用的LODOP打印控件 Lodop打印控件简单使用方法 1.安装. 2.调用LodopFuncs.js文件. 3.增加OBJECT对象 <script language="jav ...

  3. Toast工具类,Android中不用再每次都写烦人的Toast了

    package com.zhanggeng.contact.tools; /** * Toasttool can make you use Toast more easy ; * * @author ...

  4. 作为一名职高生学习Linux的心酸经历

    当你点进这篇文章的时候,一定会好奇我为什么要用“心酸”这个词,这个词已经太久没被人提起,也许心酸这种感情只能存在于一个人在追中梦想过程中内心角落吧.从小我们总是会被问这样一个问题“你的梦想是什么?”每 ...

  5. Unity 烘焙材质到单一贴图的脚本

    原地址:http://www.cocoachina.com/gamedev/gameengine/2011/0406/2756.html 这个脚本由 CocoaChina 版主 “四角钱” 分享,可以 ...

  6. [ruby on rails] 跟我学之(1)环境搭建

    环境: ubuntu 12.04 (64bit) 代理: 自己最好弄一个代理. 环境配置指令如下: sudo apt-get update sudo apt-get install curl \cur ...

  7. hping3命令

    hping3命令 网络测试 hping是用于生成和解析TCPIP协议数据包的开源工具.创作者是Salvatore Sanfilippo.目前最新版是hping3,支持使用tcl脚本自动化地调用其API ...

  8. mysql将int 时间类型格式化

    摘要 DATE_FORMAT(date,format) 根据format字符串安排date值的格式. DATE_FORMAT(date,format)  根据format字符串安排date值的格式. ...

  9. ubuntu14.04安装OpenVirteX

    官网链接: http://ovx.onlab.us/getting-started/installation/ step1: System requirements: Recommended 4 Co ...

  10. 《ASP.NET1200例》ListView控件之修改,删除与添加

    aspx <body> <form id="form1" runat="server"> <div> <asp:Lis ...