#5 #7 TLE 蒟蒻求助
查看原帖
#5 #7 TLE 蒟蒻求助
1251930
ALANYQ楼主2024/2/27 21:08
#include <bits/stdc++.h>
using namespace std;
string s;
int n,t;
bool f(int x)
{
	string s="";
	int h=0,t=0,l=0;
	while (x>0)
	{
		s=char(x%10+'0')+s;
		x/=10;
	}
	for (int i=0;i<s.size();i++)
	{
		if ((s[i]-'0')%s.size()==0) return 0;
		h+=s[i]-'0';
	}
	if (h%s.size()!=0) return 0;
	for (int i=0;i<s.size()-1;i++)
	{
		for (int j=i+1;j<s.size();j++)
		{
			if (s[i]==s[j]) return 0;
		}
	}
	int f[15];
	while (l<s.size())
	{
		l++;
		t+=s[t]-'0';
		t%=s.size();
		if (f[t]==1) return 0;
		f[t]=1;
	}
	return 1;
}
int main()
{
	cin >> s;
	while (t<s.size())
	{
		n=n*10+(s[t]-'0');
		t++;
	}
	n++;
	while (1)
	{
	    if (f(n)) break;
	    n++;
	}
	cout << n;
    return 0;
}
2024/2/27 21:08
加载中...