Ciao a tutti, ho bisogno di aiuto per risolvere il problema [Alien ABC]
Mi da pochi casi sbagliati sparsi che mi fanno ricevere 43 punti, ma non mi viene in mente nulla.
#include<bits/stdc++.h>
using namespace std;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int T;
cin>>T;
for(int t=0; t<T; t++){
string s;
cin>>s;
string parallel = s;
sort(parallel.begin(), parallel.end());
int conta = 1, x = 0;
vector <char> single;
while(conta<4 && x<s.size()){
if(parallel[x] == parallel[x+1])conta++;
else conta = 1;
x++;
}
if(conta == 4)cout<<-1;
else{
bool ans = true;
string schermo;
for(int i=0; i<s.size(); i++){
if(s[i]==s[i+1] && s[i]==s[i+2]){
schermo.push_back(s[i]);
schermo.push_back(s[i]);
schermo.push_back(s[i]);
i+=2;
}
else if(s[i]==s[i+1]){
schermo.push_back(s[i]);
schermo.push_back(s[i]);
i+=1;
}
else{
if(single.size() == 0) single.push_back(s[i]);
else{
for(int k = 0; k<single.size() && ans; k++){
if(s[i] == single[k]){
ans = false;
single.push_back(s[i]);
}
}
}
if(ans) schermo.push_back(s[i]);
else{
cout<<-1;
break;
}
}
}
if(ans){
for(int i = 0; i<schermo.size(); i++){
if(schermo[i]!=schermo[i+1]) cout<<schermo[i]<<" ";
else if(schermo[i]==schermo[i+1] && schermo[i]==schermo[i+2]){
cout<<schermo[i]<<" "<<schermo[i]<<schermo[i]<<" ";
i+=2;
}
else{
cout<<schermo[i]<<schermo[i]<<" ";
i++;
}
}
}
}
cout<<endl;
}
return 0;
}
Grazie mille in anticipo!