判断 ACdream 1202 Integer in C++
/*
分情况讨论,在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++的更多相关文章
- java中Integer,String判断相等与integer的比较大小
package sfk.bbs.test.springjsbctempletTest; import static org.junit.Assert.*; import org.junit.Test; ...
- javascript判断数字是integer还是float
function isFloat(n) { return n === +n && n !== (n|0); } function isInteger(n) { // 仅能检查32位的数 ...
- java 判断 string 转 integer 判断
NumberUtils.isDigits("1") NumberUtils.isDigits("/") 根据返回 true false 再确定是否转换即可 需要 ...
- 判断Integer值相等最好不用==(未整理)
今天在开发中判断两个Integer值相等, Integer a = 3; Duixiang duixiang = new Duixiang(); duixiang = DAO.getDuixiang( ...
- 判断Integer值相等不能用==
今天在开发中判断两个Integer值相等, Integer a = 3; Duixiang duixiang = new Duixiang(); duixiang = DAO.getDuixiang( ...
- Leetcode_8_String to Integer
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41521063 Implement atoi to conv ...
- Java 身份证判断性别获取年龄
import com.alibaba.fastjson.JSON; import org.junit.Test; import java.text.SimpleDateFormat; import j ...
- String to Integer (atoi) leetcode java
题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ca ...
- 乘风破浪:LeetCode真题_007_Reverse Integer
乘风破浪:LeetCode真题_007_Reverse Integer 一.前言 这是一个比较简单的问题了,将整数翻转,主要考察了取整和取余,以及灵活地使用long型变量防止越界的问题. 二.Reve ...
随机推荐
- Java中的final修饰符
1.什么时候可以选择final修饰符 如果想让一个类不被其他类继承,不允许在有子类,这时候就要考虑用到final来修饰. 2.用final修饰的类 首先大家要明白,用final修饰的类是不能被继承的, ...
- 用Prime31实现Google Play In-App-Blling
Android开发者想在海外赚钱,接入Google Play是不二选择,然而一堆英文文档对于像我这样的英语四级都木有过的可谓是苦恼之极.近段时间因工作需要研究了Unity接入Google Play的整 ...
- javascript对象转化为基本数据类型规则
原文:Object-to-Primitive Conversions in JavaScript 对象转化为基础数据类型,其实最终都是用调用对象自带的valueOf和toString两个方法之一并获得 ...
- win7安装ubuntu后,进入不了win7
方法一:进去ubuntu系统后,终端下输入如下命令:sudo update-grub,输入命令后,会提示寻找win7,ubuntu系统.并自动建立引导详情链接:http://zhidao.baidu. ...
- linux screen 命令详解(未验证+研究)
一.背景 系统管理员经常需要SSH 或者telent 远程登录到Linux 服务器,经常运行一些需要很长时间才能完成的任务,比如系统备份.ftp 传输等等.通常情况下我们都是为每一个这样的任务开一个远 ...
- 一步步实现Nagios监控linux主机及飞信报警
一步步实现Nagios监控linux主机及飞信报警 上篇文章介绍了在linux主机上架设nagios监控服务,并对windows主机进行服务状态变化的监控,这次我们继续上次内容. 首先实现n ...
- 【Python】Django支持事务方式
代码: with transaction.atomic(): for i in xrange(int(svc_instance_num)): tmp_fileprotect_svc_instance ...
- KDD-CUP Proposal
From 鞠源 已有 1303 次阅读 2012-11-25 21:09 |系统分类:科研笔记|关键词:会议 领域 justify 知识 KDDCUP - Competition is a stron ...
- iOS 推荐学习__bridge等ARC知识的好资料
请下载 iOS5 by Tutorials!写得很好的!
- Java for LeetCode 199 Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...