hdu 5059(模拟)
2024-09-29 10:37:21
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.
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.
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).
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
-100 100
1a0
-100 100
Sample Output
YES
NO
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 ;
}
最新文章
- JVM之内存结构
- js DOM Document类型
- selenium如何解决IE自动填充表单问题
- gd-jpeg: JPEG library reports unrecoverable error 解决办法
- Smart210学习记录-------linux驱动中断
- Hadoop no.1
- 使用仓库管理器——Sonatype Nexus的九大理由
- Word 2003 出现 向程序发送命令时出现问题 的 解决方案
- 《C#并行编程高级教程》第3章 命令式任务并行 笔记
- Clean Code&ndash;Chapter 7 Error Handling
- Java基础知识强化之集合框架笔记68:Collections类概述和成员方法(备注:Collection 和 Collections区别)
- a simple erlang process pool analysis
- mysql读写分离
- Android UI布局TableLayout
- CollectioView滚动到指定section的方法
- Greys学习笔记(未完待续)
- Mysql查询不为null值
- 最全 Linux 磁盘管理基础知识全汇总
- R语言︱数据集分组、筛选(plit – apply – combine模式、dplyr、data.table)
- python 自定义模块的发布和安装