Help him
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1948 Accepted Submission(s): 389
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 ≤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
题目大意:求给出的数据是否合法,即输入中无非法字符,大小不越界
题目分析:模拟即可......
题目分析:模拟即可......
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char str[222];
char cnt[222];
int main()
{
__int64 a, b;
__int64 temp;
char *HAHA;
while (gets(str))
{
scanf("%I64d%I64d", &a, &b);
getchar();
int len = strlen(str);
if (len >= 12) { printf("NO\n"); continue; }
temp = atol(str);
ltoa(temp, cnt, 10);
if (strcmp(cnt, str) != 0)
{
printf("NO\n"); continue;
}
if (a <= temp&&temp <= b)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}