hdu 5059 Help him(模拟)
来源:互联网 发布:什么是网络安全意识 编辑:程序博客网 时间:2024/06/05 19:25
Help him
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2510 Accepted Submission(s): 520
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.
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
Length of string is no more than 100.
The string may contain any characters other than '\n','\r'.
-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 1001a0-100 100
Sample Output
YESNO
思路:直接模拟,注意字符串会有空格,注意用long long 十位数组可能会有50E超过int范围
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main(){ char s[510]; long long a,b; while(gets(s)) { scanf("%lld %lld",&a,&b); int len=strlen(s); int flag=0; if(s[0]!='-'&&(s[0]<'0'||s[0]>'9')) flag=1; for(int i=1; i<len; i++) if(s[i]<'0'||s[i]>'9') flag=1; if(s[0]=='-'&&(len==1||s[1]=='0')) flag=1; if(len>1&&s[0]=='0') flag=1; if(flag) printf("NO\n"); else { if(len>11) printf("NO\n"); else { long long ans=0; if(s[0]=='-') { for(int i=1;i<len;i++) ans=ans*10+s[i]-'0'; ans=-ans; } else for(int i=0;i<len;i++) ans=ans*10+s[i]-'0'; if(ans>=a&&ans<=b) printf("YES\n"); else printf("NO\n"); } } getchar(); } return 0;}
0 0
- HDU-#5059 Help him(字符串+模拟)
- hdu 5059 Help him(模拟)
- HDU 5059 Help him (模拟)
- hdu 5059 Help him(模拟)
- hdu 5059 Help him
- Help him HDU 5059
- HDU 5059 help him
- HDU 5059 Help him(细节)
- HDU 5059Help him(字符串)
- HDU 5059 Help him(字符串 筛选数字 模拟)(atoi sprintf 函数)
- HDU-Help him-字符串的模拟
- Help him (BestCoder Round #12) HDU 5059
- hdu 5059 BC#12 Help him
- HDU—— 5059 Help him
- HDU 5059\BC 12B Help him
- Help him
- Help him
- 【CUGBACM15级BC第12场 B】hdu 5059 Help him
- 一幅图大致了解Android与javaEE的关系
- ST_LINK/V2 SWIM和SWD、JTAG下载口说明
- 郑帅师兄的五年博士总结
- 使用百度地图的总结
- 停止线程的两种方法
- hdu 5059 Help him(模拟)
- iOS安全–实时查看模拟器的日志输出
- nova compute报kvm权限问题
- Lyp
- Android---引导界面的制作
- mac os 连阿里云之windows server2008
- Android xml预览布局时,超出屏幕怎么看效果
- [Sencha ExtJS & Touch] singletap 和 tap的区别
- 3、MySQL基本操作:存储引擎、数据类型-----第2篇