ZeroJudge L922: The Old Castle

Due to a sudden snowstorm, you stumbled upon a long-abandoned castle. The castle had no signal, but you urgently needed to contact rescue. You searched around the castle and heard what sounded like a phone ringing at the end of a corridor. Though everything seemed eerie and terrifying, you decided to investigate to return to modern society as quickly as possible. Through a crack in the door, you saw an old telephone inside the room, but the door was tightly locked, and you needed to find the password. You found some clues from the paintings in the corridor. Each painting had a word representing numbers 1 to 9 in English, and each painting was labeled with a year. You believed that by sorting the paintings according to the years and then converting the English words on them into numbers, you could find the room's password.

Please write a program to convert the obtained information into a password.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The first line contains a positive integer N (1 <= N <= 1000), indicating the number of paintings.
Following that are N lines of input, each containing a string S and a positive integer Y (1 <= Y <= 2000), separated by a space; S is an English word representing a number from 1 to 9 (using uppercase English letters only), and Y represents the year of the painting. The test data guarantees that the years are all different.
Output a number representing the obtained password.
3
ONE 368
THREE 1980
SEVEN 1624
173
6
FOUR 1911
SIX 1914
NINE 1782
EIGHT 573
TWO 42
FIVE 987
285946

Thought Process

You can use Pair to input the string and the year together, allowing for direct sorting. You can use a Map to convert the string into numbers.

Sample Code-ZeroJudge L922: The Old Castle

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

pair<int, int> rtn (int a, int b)
{
    pair<int, int>tmp;
    tmp.first = a;
    tmp.second = b;
    return tmp;
}

int main() {
    map<string, int>MAP;
    MAP["ONE"] = 1;
    MAP["TWO"] = 2;
    MAP["THREE"] = 3;
    MAP["FOUR"] = 4;
    MAP["FIVE"] = 5;
    MAP["SIX"] = 6;
    MAP["SEVEN"] = 7;
    MAP["EIGHT"] = 8;
    MAP["NINE"] = 9;
    int N;
    cin >> N;
    vector<pair<int, int>>v;
    for (int i = 0; i<N; i++)
    {
        string str;
        int num;
        cin >> str >> num;
        v.push_back(rtn(num, MAP[str]));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i<N; i++)
    {
        cout << v[i].second;
    }
    cout << "\n";
}

//ZeroJudge L922
//Dr. SeanXD

Comments