hdu 5059(模拟)
Help him
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2500 Accepted Submission(s): 518
you know, when you want to hack someone's program, you must submit your
test data. However sometimes you will submit invalid data, so we need a
data checker to check your data. Now small W has prepared a problem for
BC, but he is too busy to write the data checker. Please help him to
write a data check which judges whether the input is an integer ranged
from a to b (inclusive).
Note: a string represents a valid integer when it follows below rules.
1. When it represents a non-negative integer, it contains only digits without leading zeros.
2. When it represents a negative integer, it contains exact one
negative sign ('-') followed by digits without leading zeros and there
are no characters before '-'.
3. Otherwise it is not a valid integer.
test cases (about 100), every case occupies two lines, the first line
contain a string which represents the input string, then second line
contains a and b separated by space. Process to the end of file.
Length of string is no more than 100.
The string may contain any characters other than '\n','\r'.
-1000000000≤a≤b≤1000000000
each case output "YES" (without quote) when the string is an integer
ranged from a to b, otherwise output "NO" (without quote).
-100 100
1a0
-100 100
NO
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std; char str[];
int main()
{
while(gets(str)){
long long a,b;
scanf("%lld%lld",&a,&b);
getchar();
if(strcmp(str,"")==){
if(a<=&&b>=) printf("YES\n");
else printf("NO\n");
continue;
}
int len = strlen(str);
if(len>){
printf("NO\n");
continue;
}
int s = ;
bool flag = false,is_nag = false;
if(str[]=='-') {
s++;
is_nag = true;
}
long long sum = ;
if(str[s]==''||!isdigit(str[s])) flag = true;
for(int i=s;i<len&&!flag;i++){
if(isdigit(str[i])){
sum = sum* + str[i]-'';
}else{
flag = true;
}
}
if(flag){
printf("NO\n");
}else{
if(is_nag) sum = -sum;
if(sum>=a&&sum<=b){
printf("YES\n");
}else{
printf("NO\n");
}
}
}
return ;
}
hdu 5059(模拟)的更多相关文章
- HDU 5059 Help him(细节)
HDU 5059 Help him 题目链接 直接用字符串去比較就可以,先推断原数字正确不对,然后写一个推断函数,注意细节,然后注意判掉空串情况 代码: #include <cstdio> ...
- HDU 5059 Help him(简单模拟题)
http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那 ...
- BestCoder12 1002.Help him(hdu 5059) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否 ...
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
- hdu 5059 简单字符串处理
http://acm.hdu.edu.cn/showproblem.php?pid=5059 确定输入的数是否在(a,b)内 简单字符串处理 #include <cstdio> #incl ...
- hdu 5012 模拟+bfs
http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...
- HDU 5059 Harry And Biological Teacher
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5069 题意:给出n个串,m个询问,每个询问(u,v),求u的一个最长后缀是v的前缀. 思路:离线.将关于u ...
- hdu 4669 模拟
思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...
- 2013杭州网络赛C题HDU 4640(模拟)
The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
随机推荐
- 海量数据处理算法—BitMap
1. Bit Map算法简介 来自于<编程珠玑>.所谓的Bit-map就是用一个bit位来标记某个元素对应的Value, 而Key即是该元素.由于采用了Bit为单位来存储数据,因此在存储空 ...
- The DOM in JavaScript
DOM : Document Object Model D is for document : The DOM cant work without a document . When you c ...
- 云容器和安全性仍然是困扰IT人士的头号问题
[TechTarget中国原创] 容器和云安全仍然是IT领域中最热门的两个话题.下面就让我们来详细探讨一下吧. 云容器风靡一时是事出有因的.如Docker这样的容器能够提高应用的可移植性,并让企业用户 ...
- 【Word Ladder II】cpp
题目: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) ...
- IntelliJ IDEA下maven Spring MVC配置
1. 导入工程:或者新建Spring web工程,可以参考博客中的Eclipse Spring MVC的方式: 2.配置Tomcat服务器,有两种方式:一是配置maven插件,而是配置本地Tomcat ...
- CSU-ACM寒假集训选拔-入门题
CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...
- python批量爬取文档
最近项目需要将批量链接中的pdf文档爬下来处理,根据以下步骤完成了任务: 将批量下载链接copy到text中,每行1个链接: 再读txt文档构造url_list列表,利用readlines返回以行为单 ...
- Docker Hadoop LAMP安装配置教程
以下教程来自九章算法. 1.How to install Dockerhttps://bupt.quip.com/YehSAR4qnGqB 2.How to set up hadoop environ ...
- hihoCoder #1758 加减
$\DeclareMathOperator{\lowbit}{lowbit}$ 题目大意 对于一个数 $x$,设它最低位的 1 是第 $i$ 位,则 $\lowbit(x)=2i$ . 例如 $\lo ...
- [HNOI2014][bzoj3572] 世界树 [虚树+dp]
题面: 传送门 思路: 一道虚树的好题,是很多虚树博客的入门题目 但是我认为这道题目出的难点和亮点不在于虚树,而在于建出虚树以后dp的思路与实现 下文中为方便描述,用势力范围来表示一个“议事处”管辖的 ...