๐Ÿ•๏ธ ICPC Sinchon/Sorting

[BOJ][C++] ๋ฐฑ์ค€ 28114๋ฒˆ : ํŒ€๋ช… ์ •ํ•˜๊ธฐ

์„ ๋‹ฌ 2024. 8. 1. 21:42
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/28114

 

 

๋ฌธ์ œ

ํ˜„๋Œ€ ๋ชจ๋น„์Šค๋Š” ๋ชจ๋นŒ๋ฆฌํ‹ฐ SW ํ•ด์ปคํ†ค, ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ฒฝ์ง„๋Œ€ํšŒ, ์ฑ„์šฉ ์—ฐ๊ณ„ํ˜• SW ์•„์นด๋ฐ๋ฏธ ๋“ฑ ๋‹ค์–‘ํ•œ SW ์ธ์žฌ ๋ฐœ๊ตด ํ”„๋กœ๊ทธ๋žจ์„ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋‹ค. ์ง€๋‚œ 2์›”์— ๊ฐœ์ตœ๋œ ๋ชจ๋นŒ๋ฆฌํ‹ฐ SW ํ•ด์ปคํ†ค์€ ๊ตญ๋‚ด 14๊ฐœ ๋Œ€ํ•™์˜ ์†Œํ”„ํŠธ์›จ์–ด ๋™์•„๋ฆฌ 20๊ฐœ ํŒ€, 70์—ฌ ๋ช…์ด ์ฐธ์—ฌํ•ด ๋ชจ๋นŒ๋ฆฌํ‹ฐ ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ ์‹ค๋ ฅ์„ ๊ฒจ๋ค˜๋‹ค.

์ˆญ์‹ค๋Œ€ํ•™๊ต ์ปดํ“จํ„ฐํ•™๋ถ€ ๋ฌธ์ œํ•ด๊ฒฐ ์†Œ๋ชจ์ž„ SCCC ๋ถ€์›๋“ค์€ ๋งค๋…„ ๋ชจ๋นŒ๋ฆฌํ‹ฐ SW ํ•ด์ปคํ†ค, SCON, ICPC์™€ ๊ฐ™์€ ํŒ€ ๋Œ€ํšŒ์—์„œ ์‚ฌ์šฉํ•  ํŒ€๋ช…์„ ์ •ํ•˜๊ธฐ ์œ„ํ•ด ๋งŽ์€ ๊ณ ๋ฏผ์„ ํ•œ๋‹ค. ์กธ์—…์„ ํ•œ ํ•™๊ธฐ ๋‚จ๊ฒจ๋‘” ์„ฑ์„œ๋Š” ๋” ์ด์ƒ ๋ถ€์›๋“ค์ด ํŒ€๋ช…์œผ๋กœ ๊ณ ํ†ต์„ ๋ฐ›์ง€ ์•Š๋„๋ก ๊ฐ€์ด๋“œ๋ผ์ธ์„ ๋งŒ๋“ค์—ˆ๋‹ค.

์„ฑ์„œ์˜ ๊ฐ€์ด๋“œ๋ผ์ธ์— ๋”ฐ๋ฅด๋ฉด ํŒ€ ์ด๋ฆ„์„ ์ง“๋Š” ๋ฐฉ๋ฒ•์€ ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

  1. ์„ธ ์ฐธ๊ฐ€์ž์˜ ์ž…ํ•™ ์—ฐ๋„๋ฅผ 100์œผ๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์„œ ์ด์–ด ๋ถ™์ธ ๋ฌธ์ž์—ด
  2. ์„ธ ์ฐธ๊ฐ€์ž ์ค‘ ์„ฑ์”จ๋ฅผ ์˜๋ฌธ์œผ๋กœ ํ‘œ๊ธฐํ–ˆ์„ ๋•Œ์˜ ์ฒซ ๊ธ€์ž๋ฅผ ๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€์—์„œ ํ•ด๊ฒฐํ•œ ๋ฌธ์ œ๊ฐ€ ๋งŽ์€ ์‚ฌ๋žŒ๋ถ€ํ„ฐ ์ฐจ๋ก€๋Œ€๋กœ ๋‚˜์—ดํ•œ ๋ฌธ์ž์—ด

์˜ˆ๋ฅผ ๋“ค์–ด 600๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ 18ํ•™๋ฒˆ ์•ˆ(AHN)์”จ, 2000๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ 19ํ•™๋ฒˆ ์ด(LEE)์”จ, 6000๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ 20ํ•™๋ฒˆ ์˜ค(OH)์”จ๋กœ ๊ตฌ์„ฑ๋œ ํŒ€์„ ์ƒ๊ฐํ•ด ๋ณด์ž. ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ํŒ€๋ช…์„ ๋งŒ๋“ค๋ฉด 181920์ด ๋˜๊ณ , ๋‘ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ํŒ€๋ช…์„ ๋งŒ๋“ค๋ฉด OLA๊ฐ€ ๋œ๋‹ค.

2000๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ 19ํ•™๋ฒˆ ์ด(LEE)์”จ, 9000๋ฌธ์ œ๋ฅผ 21ํ•™๋ฒˆ ๋‚˜(NAH)์”จ, 1000๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ 22ํ•™๋ฒˆ ๋ฐ•(PARK)์”จ๋กœ ๊ตฌ์„ฑ๋œ ํŒ€์€ ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ํŒ€๋ช…์„ ๋งŒ๋“ค๋ฉด 192122๊ฐ€ ๋˜๊ณ , ๋‘ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ํŒ€๋ช…์„ ๋งŒ๋“ค๋ฉด NLP๊ฐ€ ๋œ๋‹ค.

์„ธ ํŒ€์›์˜ ๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€์—์„œ ํ•ด๊ฒฐํ•œ ๋ฌธ์ œ์˜ ๊ฐœ์ˆ˜, ์ž…ํ•™ ์—ฐ๋„, ๊ทธ๋ฆฌ๊ณ  ์„ฑ์”จ๊ฐ€ ์ฃผ์–ด์ง€๋ฉด ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•๊ณผ ๋‘ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ๋งŒ๋“ค์–ด์ง€๋Š” ํŒ€๋ช…์„ ์ฐจ๋ก€๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์ฒซ ๋ฒˆ์งธ ํŒ€์›์ด ๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€์—์„œ ํ•ด๊ฒฐํ•œ ๋ฌธ์ œ์˜ ๊ฐœ์ˆ˜ ๐‘ƒ1, ์ž…ํ•™ ์—ฐ๋„ ๐‘Œ1, ์„ฑ์”จ ๐‘†1์ด ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์ฃผ์–ด์ง„๋‹ค.

๋‘˜์งธ ์ค„๊ณผ ์…‹์งธ ์ค„์—๋Š” ๋‘ ๋ฒˆ์งธ ํŒ€์›์˜ ์ •๋ณด ๐‘ƒ2,๐‘Œ2,๐‘†2์™€ ์„ธ ๋ฒˆ์งธ ํŒ€์›์˜ ์ •๋ณด ๐‘ƒ3,๐‘Œ3,๐‘†3์ด ์ฒซ์งธ ์ค„๊ณผ ๊ฐ™์€ ํ˜•์‹์œผ๋กœ ์ฃผ์–ด์ง„๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ๋งŒ๋“  ํŒ€๋ช…์„ ์ถœ๋ ฅํ•œ๋‹ค.

๋‘˜์งธ ์ค„์— ๋‘ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ๋งŒ๋“  ํŒ€๋ช…์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

ํ’€์ด

์ž…๋ ฅ ๋ฐ›์„ ๋•Œ ์ž…ํ•™ ์—ฐ๋„๋Š” ๋”ฐ๋กœ ๋ฐ›์•„๋„ ๋œ๋‹ค.

ํ•˜์ง€๋งŒ ๋ฌธ์ œ ํ•ด๊ฒฐ ์ˆ˜์™€ ์„ฑ(์ด๋ฆ„)์€ ํ•จ๊ป˜ ํ™œ์šฉํ•ด์•ผํ•˜๋ฏ€๋กœ pair์„ ์ด์šฉํ•ด์„œ ํ•œ๋ฒˆ์— ์ž…๋ ฅ๋ฐ›์•„ ํ•œ ๋ฐฐ์—ด์— ์ €์žฅํ•ด์ฃผ์ž

    vector<int> year(NUM);
    vector<ci> solveName(NUM);
    
    for(int i=0; i<NUM; i++) {
        int solve; string name;
        cin >> solve >> year[i] >> name;
        solveName[i] = {solve, name};
    }

 

 

์ฒซ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ํŒ€ ์ด๋ฆ„ ์ง“๊ธฐ

string solution1(vector<int>&year) {
    vector<int> v;
    for(int i : year) {
        v.push_back(i%100);
    }
    
    sort(v.begin(), v.end());
    
    string s = "";
    for(int i : v) {
        s += to_string(i);
    }
    
    return s;
}

 

 

๋‘๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ์ด๋ฆ„์ง“๊ธฐ

bool cmp(ci a, ci b) {
    return a.first > b.first;
}

string solution2(vector<ci>&solveName) {
    sort(solveName.begin(), solveName.end(), cmp);
    
    string s = "";
    for(ci i : solveName) {
        s += i.second[0];
    }
    
    return s;
}

 

์ •๋‹ต์ฝ”๋“œ

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int NUM = 3;

typedef pair<int, string> ci;

string solution1(vector<int>&year) {
    vector<int> v;
    for(int i : year) {
        v.push_back(i%100);
    }
    
    sort(v.begin(), v.end());
    
    string s = "";
    for(int i : v) {
        s += to_string(i);
    }
    
    return s;
}

bool cmp(ci a, ci b) {
    return a.first > b.first;
}

string solution2(vector<ci>&solveName) {
    sort(solveName.begin(), solveName.end(), cmp);
    
    string s = "";
    for(ci i : solveName) {
        s += i.second[0];
    }
    
    return s;
}

int main() {
    vector<int> year(NUM);
    vector<ci> solveName(NUM);
    
    for(int i=0; i<NUM; i++) {
        int solve; string name;
        cin >> solve >> year[i] >> name;
        solveName[i] = {solve, name};
    }
    
    cout << solution1(year) << "\n" << solution2(solveName);
    
    return 0;
}
๋ฐ˜์‘ํ˜•