Help him

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

牛B大神神奇的代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
const int N = 105;
char s[N], t[N];
int a, b, c;
int solve()
{
    if(sscanf(s, "%d", &c) != 1) 
        return 0;
    sprintf(t, "%d", c);
    if(strcmp(s, t) != 0) return 0;
    return a<=c && c<=b;
}
int main()
{
    while(gets(s))
    {
        scanf("%d%d", &a, &b);
        getchar();
        int ans = solve();
        puts(ans ? "YES" : "NO");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值