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,第二长递增子序列是 ...
随机推荐
- 洛谷P2279 [HNOI2003]消防局的设立
题目描述 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料,人类只修建了n-1条道路来连接这些基地,并且每两个基地都能够通过道路到达,所以所有的基地形成了一个巨大的树状 ...
- IRP IO_STACK_LOCATION 《寒江独钓》内核学习笔记(1)
在学习内核过滤驱动的过程中,遇到了大量的涉及IRP操作的代码,这里有必要对IRP的数据结构和与之相关的API函数做一下笔记. 1. 相关阅读资料 <深入解析 windows 操作系统(第4版,中 ...
- vim下使用ctags+taglist
好几年前用过,但是后来就生疏了,好其次都没法鼓起勇气再捡起来...今天不得不用,那既然捡起来了,就好好的记录一下. 简介及安装 ctags是一个应用程序,可以用它来生产当前目录下所有c文件中变量和函数 ...
- 初学JDBC,JDBC工具类的简单封装
//工具类不需要被继承 public final class JdbcUtils{ //封装数据库连接参数,便于后期更改参数值 private static String url="jdbc ...
- 我对 impress.js 源码的理解
源码看了两天,删掉了一些优化,和对 ipad 的支持,仅研究了其核心功能的实现,作以下记录. HTML 结构如下: <!doctype html> <html lang=" ...
- FCKeditor漏洞利用
FCKeditor漏洞利用 查看编辑器版本 FCKeditor/_whatsnew.html fckeditor/editor/dialog/fck_about.html —————————————— ...
- html中input输入框屏蔽鼠标右键
<label> <input id="ckdestinationId" type="text" oncontextmenu="ret ...
- Visual Studio 2013 中 mysql 使用 EF6
1.web.config <configSections> <!-- For more information on Entity Framework configuration, ...
- Linq实现DataTable的分组统计
DataTable dt = GetTestData(10); //获取10条测试数据 var queryByService = from r in dt.AsEnumerable() group r ...
- C#操作XML类
XML转换成HTML 1.//装载xsl XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("output. ...