Skip to content

Instantly share code, notes, and snippets.

@diego9627
Created October 24, 2012 06:49
Show Gist options
  • Save diego9627/3944440 to your computer and use it in GitHub Desktop.
Save diego9627/3944440 to your computer and use it in GitHub Desktop.
Fixture
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int N;
string horario[10],resp;
pair<bool,int> borrar(int i){
pair<bool,int> res(false,0);
if(!horario[i].empty()){
int t=horario[i][0]-'0';
if(!horario[t].empty()){
res=make_pair(i==horario[t][0]-'0',t);
if(res.first){
horario[t].erase(horario[t].begin());
horario[i].erase(horario[i].begin());
}
}
}
return res;
}
int main(){
int i,r,s;
queue<int> enteros;
cin >> N;
horario[1]="0";
for(i=2;i<1+N;i++){
cin >> horario[i];
s+=horario[i].size();
}
pair<bool,int> t;
for(i=2;i<1+N;i++){
if((i==horario[horario[i][0]-'0'][0]-'0')||horario[i][0]-'0'==1) enteros.push(i);
}
while(!enteros.empty()){
r=enteros.front();
if(horario[r][0]-'0'!=1){
t=borrar(r);
if(t.first){
enteros.push(r);
enteros.push(t.second);
}
enteros.pop();
}
else{
horario[r].erase(horario[r].begin());
resp+='0'+r;
}
}
cout << resp;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment