Uva 12015 Solution

#include<bits/stdc++.h>
using namespace std;
struct anik
{
    string s;
    int a, b;
};
int main()
{
    int n, i, j, k;
    while(cin >> n)
    {
        for(k=1;k<=n;k++)
        {
            vector<anik>v;
            string ch;
            int r;
            for(j=1;j<=10;j++)
            {
                cin >> ch >> r;
                v.push_back({ch, r, j});
            }
            for(i=0;i<10-1;i++)
            {
                for(j=0;j<10-i-1;j++)
                {
                    if(v[j].a < v[j+1].a)
                    {
                        swap(v[j].s, v[j+1].s);
                        swap(v[j].a, v[j+1].a);
                        swap(v[j].b, v[j+1].b);
                    }
                    if(v[j].a == v[j+1].a)
                    {
                        if(v[j].b > v[j+1].b)
                        {
                            swap(v[j].s, v[j+1].s);
                            swap(v[j].a, v[j+1].a);
                            swap(v[j].b, v[j+1].b);
                        }
                    }
                }
            }
            int t = v[0].a;
            i = 0;
            cout << "Case #" << k << ":" <<endl;
            while(t == v[i].a)
            {
                cout << v[i].s << endl;
                i++;
            }
        }
    }
    return 0;
}

Comments