Help him

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2500    Accepted Submission(s): 518

Problem Description
As
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.
 
Input
Multi
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

 
Output
For
each case output "YES" (without quote) when the string is an integer
ranged from a to b, otherwise output "NO" (without quote).
 
Sample Input
10
-100 100
1a0
-100 100
 
Sample Output
YES
NO
 
Source
 
题意:判断一个字符串是否符合要求:
假设为正数,不能有前导0
假设为负数,最前面有 - 号,整数部分不能有前导0
这个串必须在 [a,b]之间
这个题坑的地方:判断 0 ,一定开longlong,我就被long long 坑死了。然后还有一点就是gets()读入。
#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(模拟)的更多相关文章

  1. HDU 5059 Help him(细节)

    HDU 5059 Help him 题目链接 直接用字符串去比較就可以,先推断原数字正确不对,然后写一个推断函数,注意细节,然后注意判掉空串情况 代码: #include <cstdio> ...

  2. HDU 5059 Help him(简单模拟题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那 ...

  3. BestCoder12 1002.Help him(hdu 5059) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否 ...

  4. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  5. hdu 5059 简单字符串处理

    http://acm.hdu.edu.cn/showproblem.php?pid=5059 确定输入的数是否在(a,b)内 简单字符串处理 #include <cstdio> #incl ...

  6. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

  7. HDU 5059 Harry And Biological Teacher

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5069 题意:给出n个串,m个询问,每个询问(u,v),求u的一个最长后缀是v的前缀. 思路:离线.将关于u ...

  8. hdu 4669 模拟

    思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...

  9. 2013杭州网络赛C题HDU 4640(模拟)

    The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

随机推荐

  1. 大数据小项目之电视收视率企业项目08--》MapReduce编写之Wordcount

    编程规范 (1)用户编写的程序分成三个部分:Mapper,Reducer,Driver(提交运行mr程序的客户端) (2)Mapper的输入数据是KV对的形式(KV的类型可自定义) (3)Mapper ...

  2. 第2章 CentOS7集群环境配置

    目录 2.1 关闭防火墙 2.2 设置固定IP 2.3 修改主机名 2.4 添加用户 2.5 修改用户权限 2.6 新建目录 2.7 安装JDK 1.卸载系统自带的JDK 2.安装JDK 2.8 克隆 ...

  3. Python学习笔记(二):数据类型

    一.python中的数据类型 python中的数据类型包括:整型.浮点型.布尔型.字符串类型 整型(int)和浮点型(float) Python中的整型只有int,没有short.long:浮点型fl ...

  4. 理解 Objective-c "属性"

    理解 Objective-c "属性" @property 是OC中能够快速定义一个属性的关键字,如下我们定义一个属性. @property NSString *String; 这 ...

  5. BFS:CF356C-Compartments

    C. Compartments time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. [BZOJ3625][CF438E]小朋友和二叉树

    题面 Description 我们的小朋友很喜欢计算机科学,而且尤其喜欢二叉树. 考虑一个含有\(n\)个互异正整数的序列\(c_1,c_2,\ldots,c_n\).如果一棵带点权的有根二叉树满足其 ...

  7. Linux命令之---rm

    命令简介 rm命令为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除.对于链接文件,只是删除了链接,原有文件均保持不变. rm是一个危险的命令,使用的时候要特别当 ...

  8. 1026: [SCOI2009]windy数(数位dp)

    1026: [SCOI2009]windy数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9016  Solved: 4085[Submit][Sta ...

  9. IT帮2019年2月线下活动【定义工作,解读自我】之站桩练习

    2019年2月IT帮线下活动[定义工作,解读自我] 昨天的活动收获很大,全面的总结周老师会另写一篇来帮助大家回顾.我想说一下其中最打动我的一句话:“只有你能决定你有多优秀!” “工作中把自己当成企业家 ...

  10. Leetcode 650.只有两个键的键盘

    只有两个键的键盘 最初在一个记事本上只有一个字符 'A'.你每次可以对这个记事本进行两种操作: Copy All (复制全部) : 你可以复制这个记事本中的所有字符(部分的复制是不允许的). Past ...