题目链接: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. jQuery返回顶部代码组件

    非原创,拿来修改,样式可自定义,div,img都可以,效果如下: 下载地址:http://files.cnblogs.com/files/EasonJim/jquery.topback.rar 项目相 ...

  2. poj1056 (Trie入门)寻找字符串前缀

    题意:给你一堆字符串,问是否满足对于任意两个字符串a.b,a不是b的前缀 字典树==前缀树==Trie树 trie入门题,只用到了insert和query操作 #include <cstdio& ...

  3. java中获取本地文件的编码

    import java.util.*; public class ScannerDemo { public static void main(String[] args) { System.out.p ...

  4. TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133

    程序代码  class Person:      #constructor      def __init__(self,name,sex):           self.Name = name   ...

  5. HD2255奔小康赚大钱(最大权匹配模板)

    奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  6. app工程构成

    1)工程配置文件: 2)源代码: 3)资源文件.

  7. MyEclipse修改项目名称后,部署到 tomcat问题

    问题描述: 修改项目名称后,部署到tomcat问题 解决方案: 项目->属性->myelcipse->web下,修 改web context root就可! 要在eclipse里面改 ...

  8. spring AOP面向切面编程学习笔记

    一.面向切面编程简介: 在调用某些类的方法时,要在方法执行前或后进行预处理或后处理:预处理或后处理的操作被封装在另一个类中.如图中,UserService类在执行addUser()或updateUse ...

  9. angular-ngSanitize模块-linky过滤器详解

    本篇主要讲解angular中的linky这个过滤器.此过滤器依赖于ngSanitize模块. linky能找出文本中的链接,然后把它转换成html链接.什么意思,就是说,一段文本里有一个链接,但是这个 ...

  10. 教你安装漂亮的Arc GTK主题

    导读 近日,我们又发现了一款深受 Linux 用户喜爱的桌面主题 — Arc GTK,Arc GTK 主题已被很多 GNU/Linux 操作系统支持和采用,其中就包括即将到来的 Linux Mint ...