题目链接: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) 解题报告的更多相关文章

  1. 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,使得 ...

  2. BestCoder12 1001.So easy(hdu 5058) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5058 (格式有点问题,为了方便阅读---整个复制下来吧) 题目意思:给出两个长度都为 n 的集合你,问 ...

  3. BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908 题目意思:给出 一个从1~N 的排列你和指定这个排列中的一个中位数m,从这个排列中找出长度为奇数 ...

  4. hdu 1002.A + B Problem II 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...

  5. BestCoder17 1002.Select(hdu 5101) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...

  6. BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...

  7. 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,问是否在每个数 ...

  8. BestCoder20 1002.lines (hdu 5124) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...

  9. BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...

随机推荐

  1. Rdesktop

    linux远程windows rdesktop是一个开放源码的Window   NT中断服务器的客户端,它实现了远程桌面协议(RDP) rdesktop-1.7.0.tar 下载地址:http://d ...

  2. opencv笔记2:图像ROI

    time:2015年 10月 03日 星期六 12:03:45 CST # opencv笔记2:图像ROI ROI ROI意思是Region Of Interests,感兴趣区域,是一个图中的一个子区 ...

  3. POJ1141 Brackets Sequence

    Description Let us define a regular brackets sequence in the following way: 1. Empty sequence is a r ...

  4. java将数据写入到txt文件中(txt有固定的格式)

    java将数据写入到txt文件中,这个应该对于学过java I/O的人来说是很简单的事情了,但是如果要将数据以固定的格式写入到txt文件中,就需要一定的技巧了. 这里举个简单的例子,以供参考: 比如我 ...

  5. foeach集合遍历

    package number; public class Number { public static void main(String[] args) { int[] arr={5,2,1,0,3, ...

  6. groovy-输入输出

    Groovy为I/O提供了一系列的helper methods ,所有的这些方法都适用于标准的 Java Reader/Writer ,InputStream/OutputStream 和File 以 ...

  7. MVC区域 视图必须派生自 WebViewPage 或 WebViewPage<TModel>

    http://blog.csdn.net/iack_ji/article/details/16965885 今天在学习 mvc区域时,将区域控制器类 外迁到其他的程序集的练习中出现了"视图必 ...

  8. MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解决办法

    MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解决办法 1 问题 [root@localhost m ...

  9. Spring实战学习笔记之SpEL表达式

            在Spring XML配置文件中装配Bean的属性和构造参数都是静态的,而在运行期才知道装配的值,就可以使用SpEL实现         SpEL表达式的首要目标是通过计算获得某个值. ...

  10. js中test()函数在正则中使用

    test() 方法用于检测一个字符串是否匹配某个模式. 返回一个 Boolean 值,它指出在被查找的字符串中是否匹配给出的正则表达式. regexp.test(str) 参数 regexp 必选项. ...