题目链接: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. C语言中常用的string.h的字符函数

    strcmp 字符串比较函数 原型: int strcmp(char *str1, char *str2); 例子: ) printf("buffer 1 is greater than b ...

  2. ssh整合常见的错误

    1.报错信息:java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refres ...

  3. Java编程思想学习(五) 复用类

    1.继承与组合 复用类的方法有两种:继承与组合.继承就不多说了,组合就是直接在类中new一个对象. 数组也是对象,使用数组也是组合的一种. 2.初始化基类 当创建一个导出类的对象时,该对象包含一个基类 ...

  4. Java的多线程机制系列:(三)synchronized的同步原理

    synchronized关键字是JDK5之实现锁(包括互斥性和可见性)的唯一途径(volatile关键字能保证可见性,但不能保证互斥性,详细参见后文关于vloatile的详述章节),其在字节码上编译为 ...

  5. BZOJ-1024 生日快乐 DFS+一丝sb的数学思考

    1024: [SCOI2009]生日快乐 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 1948 Solved: 1391 [Submit][Statu ...

  6. firefox(ff)下无法显示bootstrap图标问题的解决方案(转)

    原文链接: http://www.th7.cn/web/html-css/201502/82548.shtml 后在网上搜到了解决方案,在此分享以供各位遇到问题的同好参考:在ff的地址栏中输入“abo ...

  7. JSP/Servlet基础语法

    相关学习资料 http://my.oschina.net/chape/blog/170247 http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp ...

  8. python二维数组

    和c c++不一样 过程如下: #-*- coding:utf-8 -*- t = [[ 0 for i in range(5)]for j in range(5)] for i in range(5 ...

  9. QA要懂的Linux命令

    <一>软件安装相关QA经常需要安装测试软件(jmeter.Mock.python环境搭建.java环境搭建),或者配置测试环境(nginx.ci等),需要了解linux下如何安装软件.在工 ...

  10. JS小记

    好记性不如烂笔头. 1.document.ElementFromPoint:根据坐标获得元素 2.有时候要操作DOM页面,但是得不到预期结果,很可能是因为页面还没加载完成,在console控制台可以看 ...