#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
char s[105];
ll a,b;
while(gets(s))
{
cin>>a>>b;
getchar();
int flag=0,flag1=0,flag2=0;
int len=strlen(s);
if(len==0){cout<<"NO"<<endl;continue;}
int mark1=0,mark2=0,mark=0;
int over=0;
for(int i=0;i<len;i++)///筛选含数字的字符串,包括'-'
{
if(s[i]>'9'||s[i]<'0')
{
if(s[i]!='-')
{mark1=1;break;}
else if(s[i]=='-'&&i!=0){mark=1;break;}
}
}
if(mark1||mark){cout<<"NO"<<endl;continue;}
else
{
if(s[0]=='-')
{
if(len>=12)flag1=1;else mark2=1;///判断为负数
}
else///正数
{
if(len>=11)flag2=1;
if(s[0]=='0'&&len!=1){over=1;cout<<"NO"<<endl;}
}
}
if(flag1||flag2){cout<<"NO"<<endl;continue;}
if(!over)
{
ll sum=0;
if(mark2)
{
if(len==1){cout<<"NO"<<endl;continue;}
if(s[1]=='0'){cout<<"NO"<<endl;continue;}
else
{
for(int i=len-1;i>=1;i--)
{
sum+=int(s[i]-'0')*pow(10.0,len-1-i);
}
sum=-sum;
if(sum>=a&&sum<=b)cout<<"YES"<<endl;else cout<<"NO"<<endl;
}
}
else
{
for(int i=len-1;i>=0;i--)
{
sum+=int(s[i]-'0')*pow(10.0,len-1-i);
}
if(sum>=a&&sum<=b)cout<<"YES"<<endl;else cout<<"NO"<<endl;
}
}
}
return 0;
}
HDU 5059 help him
最新推荐文章于 2019-02-18 10:54:51 发布
http://acm.hdu.edu.cn/showproblem.php?pid=5059
这题太坑了啊 注意输入字符长度为0时输出“NO”,还要注意空格。用gets()和cin>>a>>b 时别忘了去换行 getchar()一下就行
写的比较水~