문제 바로가기
접근방법
- 배열에 입력한 문자열을 숫자로 바꾸어 넣어준다.
- 배열을 정렬한다.
- 다시 그 배열을 문자열로 출력한다.
슈도코드
nums[];
if str == nums[i]
q.push(i)
if q.top() == i
print nums[i]
q.pop()
풀이
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
int test_case, length, valueNum = 1;
string test_num, str;
string nums[10] = { "ZRO", "ONE", "TWO", "THR", "FOR", "FIV", "SIX", "SVN", "EGT", "NIN" };
priority_queue<int, vector<int>, greater<int>> q1;
void inpiut_strToint() {
for (int w = 0; w < length; w++) {
cin >> str;
for (int j = 0; j < 10; j++) {
if (str == nums[j]) {
q1.push(j);
break;
}
}
}
}
void print_intTostr() {
for (int w = 0; w < length; w++) {
for (int j = 0; j < 10; j++) {
if (q1.top() == j) {
cout << nums[j] << " ";
q1.pop();
break;
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> test_case;
for (int i = 1; i <= test_case; i++) {
cin >> test_num >> length;
inpiut_strToint();
cout << test_num << "\n";
print_intTostr();
}
return 0;
}