发个第三题的吧 #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long st; typedef pair<int,int> P; typedef pair<int,pair<int,int>> PP; bool mycheck(char a,char b,char c){ if(a>b)swap(a,b); if(b>c)swap(b,c); if(a>b)swap(a,b); if(a==b&&b==c)return true; if(a+1==b&&b+1==c)return true; return false; } bool check3(string &s,vector<int>& fl,int sum){ if(sum<=0)return true; for(int i=0;i<s.size();i++) for(int j=i+1;j<s.size();j++) for(int k=j+1;k<s.size();k++) if(fl[i]==0&&fl[j]==0&&fl[k]==0&&mycheck(s[i],s[j],s[k])) { fl[i]=1,fl[j]=1,fl[k]=1; if(check3(s,fl,sum-3))return true; fl[i]=0,fl[j]=0,fl[k]=0; } return false; } bool check2(string &s){ vector<int> fl(20); for(int i=0;i<s.size();i++) for(int j=i+1;j<s.size();j++) if(s[i]==s[j]) { fl[i]=1,fl[j]=1; if(check3(s,fl,s.size()-2))return true; fl[i]=0,fl[j]=0; } return false; } bool check(string& s){ if(s.size()==0)return false; return check2(s); } int main() { freopen("input", "r", stdin); string s,ans; while(cin>>s) { unordered_map<char,int> um; for(char c:s)um[c]++; for(int i=1;i<10;i++){ string temp=s; if(um['0'+i]>=4)continue; temp.push_back('0'+i); if(check(temp))ans.push_back('0'+i); } if(ans.size()!=0) cout<<ans<<endl; else cout<<0<<endl; } return 0; }