题目链接:https://vjudge.net/problem/SPOJ-ABSURD

 

解题思路:

如果左端点和右端点数字长度不一样,那么就是2没跑了.

否则找到连个端点数从最高位开始第一个不相同的数然后判断这位数可以取0或者5或者其他数,后面的位数都可以是0了.

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[20],b[20];
bool check(int x,int len)
{
	for(int i=x;i<len;i++)
	if(a[i]!='0') return 0;
	return 1;
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		ll n;
		scanf("%lld",&n);
		ll c;
		sprintf(a,"%lld",n);
		int len = strlen(a);
		for(int i = len-1; i >= 0; i--)
			if(a[i]!='0'){
				if(a[i]=='5')
					c = 2*(i+1)-1;
				else
					c = 2*i+2;
				break;
			}
		ll l,r;
		r = n*105/100;
		l = (n*95-1)/100+1;
		sprintf(a,"%lld",l);
		sprintf(b,"%lld",r);
		int lena = strlen(a),lenb = strlen(b); 
		if(lena!=lenb){
			if(c>2) puts("absurd");
			else puts("not absurd");
		}else{
			int i,ret;
			for(i=0;i<lena;i++)
			if(a[i]!=b[i]) break;
			if(i==lena||(a[i]=='0'&&check(i+1,lena))){
				while(a[i]=='0') i--;
				if(a[i]=='5') ret = (i+1)*2 - 1;
				else ret = (i+1)*2;
			}else{
				int l,r;
				if(check(i+1,lena)) l = a[i]-'0',r = b[i]-'0';
				else l = a[i]-'0'+1,r = b[i]-'0';
				if(l<=5&&r>=5) ret = (i+1)*2 - 1;
				else ret = (i+1)*2;
			}
			if(c>ret) puts("absurd");
			else puts("not absurd");
		}
	}
	return 0;
}