BestCoder12 1002.Help him(hdu 5059) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059


题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否是合法的整数,如果是的话问是否在[a, b] 范围内,是则输出 YES,否则输出 NO
合法的整数:(1)非负整数:只有数字,没有前导0
(2)负数:负号后面只能跟着数字,负号前没有任何字符
首先这条题感觉不是出得太好,不过都是硬着头皮学人家做啦。反正一些很变态的数据可能还是过不了,但却AC的。
模拟题一般都是比较恶心的!!!
AC 代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std; typedef __int64 LL; inline int check(string s, int st)
{
int f = ; // 初始化很重要!
for (int i = st; i < s.size(); i++)
{
f = ;
if (s[i] < '' || s[i] > '')
break;
f = ;
}
return f;
} inline LL judge(string s, int sign, int st)
{
LL num = ;
for (int i = st; i < s.size(); i++)
num = num * + (s[i]-'');
num *= sign;
return num;
} int main()
{
int a, b;
string s;
while (getline(cin, s))
{
scanf("%d%d", &a, &b);
getchar();
int flag = ;
if (s[] == '-')
flag = check(s, );
else
flag = check(s, );
// 特判0的几种情况
if (s[] == '' && s.size() != )
flag = ;
if (s[] == '' && s.size() == )
flag = ;
if (s[] == '-' && s[] == '')
flag = ;
if (!flag)
{
printf("NO\n");
continue;
}
// 处理到这里之后就是合法整数了,之后从string转换成__int64
LL ans = ;
if (s[] == '-')
ans = judge(s, -, );
else
ans = judge(s, , );
if (s.size() == || s.size() >= || ans < a || ans > b) // 有长度限制,不能超出区间
printf("NO\n");
else
printf("YES\n");
}
return ;
}
BestCoder12 1002.Help him(hdu 5059) 解题报告的更多相关文章
- BestCoder18 1002.Math Problem(hdu 5105) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...
- BestCoder12 1001.So easy(hdu 5058) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5058 (格式有点问题,为了方便阅读---整个复制下来吧) 题目意思:给出两个长度都为 n 的集合你,问 ...
- BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 题目意思:给出 一个从1~N 的排列你和指定这个排列中的一个中位数m,从这个排列中找出长度为奇数 ...
- hdu 1002.A + B Problem II 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...
- BestCoder17 1002.Select(hdu 5101) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...
- BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...
- BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...
- BestCoder20 1002.lines (hdu 5124) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...
- BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...
随机推荐
- TYVJ P1403 [NOIP2010]关押罪犯
TYVJ的编译器总是要搞点岔子出来,上次是double必须用f输出而不能用lf,这次又不知道为何CE 于是去了洛谷P1525测试,AC 题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1 ...
- 使用PPA在Ubuntu上安装php5.4~5.6,7
使用PPA在Ubuntu上安装php5.4~5.6,7 sudo apt-get install software-properties-common sudo add-apt-repository ...
- jquery autocomplete 简单实用例子
<link href="../../themes/default/css/jquery.ui.all.css" rel="stylesheet" type ...
- msmms (二) sms与mms 简述!
mms 锁定 本词条由“科普中国”百科科学词条编写与应用工作项目 审核 . MMS是英文缩写,它可以是Membership Management System的缩写,中文译名为会员管理系统.也可以是M ...
- PHP雪花背景验证码
ValidateCode.class.php 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...
- SVM算法入门
转自:http://blog.csdn.net/yangliuy/article/details/7316496SVM入门(一)至(三)Refresh 按:之前的文章重新汇编一下,修改了一些错误和不当 ...
- POJ2823 Sliding Window (单调队列)
POJ2823 Sliding Window Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 38342 Accepte ...
- Jquery Validate 正则表达式实用验证代码
jQuery.validate 的正则验证功能,包括手机号码.电话号码.邮政编码.QQ号码.IP地址.字母和数字.中文的验证等. 手机号码验证 以下为引用内容: jQuery.validator.a ...
- $key 的用法
<?php $attr=array("a","b","c","d"); //$key,默认是主键值,$value, ...
- [Effective JavaScript 笔记]第48条:避免在枚举期间修改对象
注册列表示例 一个社交网络有一组成员,每个成员有一个存储其朋友信息的注册列表. function Member(name){ this.name=name; this.friends=[]; } va ...