Pages

Sunday, June 3, 2012

482 - Permutation Arrays


//
// main.cpp
// 482 - Permutation Arrays
//
// Created by Panks on 30/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
int main (int argc, const char * argv[])
{
int t, count=0;
string line1, line2;
int index;
string value;
vector<pair<int, string> > store;
cin>>t;
getchar();
while (t--) {
getchar();
count++;
getline(cin, line1);
getline(cin, line2);
stringstream ss1(line1), ss2(line2);
while (ss1>>index) {
ss2>>value;
store.push_back(pair<int, string>(index, value));
}
sort(store.begin(), store.end());
if (count>1) {
cout<<endl;
}
for (int i=0; i<store.size(); i++) {
cout<<store[i].second<<endl;
}

store.clear();
}
return 0;
}

3 comments:

  1. i dont understand how just you sorted the vector , i think it must be tow vectors , sort them , then map each element from vec1 with vec2 .
    can you please explain your idea ?
    thanks

    ReplyDelete
  2. he sorts because of this line :
    cout<<store[i].second<<endl;

    ReplyDelete