Hello everybody
I’m trying to solve the Kattis problem “Music your Way” Music Your Way but in the third test I receive a wrong answer. I would be very grateful if you can help me to know what is my mistake to keep improving. The code is pasted below. Thanks
#include <bits/stdc++.h>
using namespace std;
typedef vector< vector<string> > vs;
vector <string> comandos;
string cadena;
bool cmp(vector<string> a, vector<string> b){
int pos;
for(int i=0; i<comandos.size(); i++) {
if(comandos[i]==cadena) {
pos=i;
break;
}
}
return a[pos]<b[pos];
}
int main(){
int m, n, cont=0;
char aux;
cadena="";
while(cin.get(aux) && aux!='\n'){
if(aux!=32) cadena+=aux;
else{
comandos.push_back(cadena);
cadena="";
}
}
comandos.push_back(cadena);
cin>>m;
cin.ignore();
vs canciones (m, vector<string>(comandos.size()));
for(int i=0; i<m; i++){
for(int j=0; j<comandos.size(); j++){
cin>>canciones[i][j];
}
}
cin>>n;
cin.ignore();
while(n--){
if(cont!=0) cout<<"\n";
cont++;
vs vaux=canciones;
cin>>cadena;
stable_sort(vaux.begin(), vaux.end(), cmp);
cout<<comandos[0];
for(int i=1; i<comandos.size(); i++) cout<<" "<<comandos[i];
cout<<"\n";
for(int i=0; i<m; i++){
for(int j=0; j<comandos.size(); j++){
cout<<vaux[i][j];
if(j!=comandos.size()-1) cout<<" ";
}
cout<<"\n";
}
}
return 0;
}