81分求助
查看原帖
81分求助
838926
very_easy楼主2023/12/25 12:22

赛时代码,大体思路就是相邻且相同的话只有2和3或者9和0,特判WA on #2

#include<bits/stdc++.h>
using namespace std;
int main(){
	long long l,r;
	cin>>l>>r;
	if((l==r&&l%10==2)||(l==r&&l%10==9)){
		cout<<1;
		return 0;
	}
	for(long long i=l;i<=r;i++){
		if(i%10==2&&i+1<=r){
			cout<<2;
			return 0;
		}
		int tmp=i;
		int cnt0=0,cnt3=0,cnt2=0,cnt9=0;
		while((tmp%10==9||tmp%10==2)&&tmp){
			if(tmp%10==9) cnt9++;
			if(tmp%10==2) cnt2++;
			tmp/=10;
		}
		tmp=i+1;
		while((tmp%10==3||tmp%10==0)&&tmp){
			if(tmp%10==3) cnt3++;
			if(tmp%10==0) cnt0++;
			tmp/=10;
		}
		if(cnt2==cnt3&&cnt0==cnt9&&cnt2!=0){
			cout<<2;
			return 0;
		}
	}
	cout<<1;
	return 0;
}
2023/12/25 12:22
加载中...