题目描述 https://www.luogu.org/problemnew/show/P5238
主要考虑的有几点
1.单独"-"是不行的,-0类似的也不行,00,01,02这样的也不行,都算不合法。
2.在合法的前提下,位数超过了20就说明不在范围内了。
3.把字符数组转换为数,再与l r判断。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll l,r;
int main()
{ int t;
scanf("%lld%lld%d",&l,&r,&t);
while(t--)
{
char ch[100005];
cin>>(ch+1); int len=strlen(ch+1);
if(ch[1]=='-')
if(ch[2]=='0'||len==1)//-0 -
{
puts("1");
continue;
}
if(ch[1]=='0'&&len!=1)//00 01
{
puts("1");
continue;
}
if(ch[1]=='-'&&len>20)
{
puts("2");
continue;
}
if(ch[1]!='-'&&len>19)
{
puts("2");
continue;
}
unsigned long long tmp=0;
ll x=0;
if(ch[1]=='-')
{
sscanf(ch+2,"%llu",&tmp);//把字符数组转换为数
if(tmp>(1LL<<63))
{
puts("2");
continue;
}
x=-tmp;
}
else
{
sscanf(ch+1,"%llu",&tmp);
if(tmp>=(1LL<<63))
{
puts("2");
continue;
}
x=tmp;
}
if(x<l||x>r)
{
puts("2");
continue;
}
puts("0");
}
return 0;
}