ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1542. Autocompletion

What about 10 test? My program here.
Posted by Alexander Goncharov 6 Aug 2012 16:25
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

bool compar1(pair<string, int> a, pair<string,int> b)
{
     if (a.second>b.second) return true;
     else return false;
}

int main(int argc, char *argv[])
{
    int n = 0;
    cin >> n;
    vector<pair<string, int> > v(n);
    for (int i = 0; i<n; i++) {
        string tmp;
        int num;
        cin >> tmp;
        cin >> num;
        v.push_back(make_pair(tmp, num));
    }
    sort(v.begin(), v.end(), compar1);
    int m = 0;
    cin >> m;
    for (int i = 0; i<m; i++) {
        string str;
        cin >> str;
        for (int j = 0; j<n; j++) {
            if (v[j].first.find(str)==0&&j<10) {
               cout << v[j].first << endl;
            }
        }
        if (i!=m-1) cout << endl;
    }
    system("PAUSE");
    return 0;
}