구현문제 같다. TL이 넉넉해서 무지성으로 입력받아 sort해도 풀릴꺼같다.

내가 푼 방식은 어차피 작은 수부터 출력하므로 0부터 9까지 몇번 나오는지만 알면 된다.

그 후 0부터 9만큼 들어온 만큼 출력하면 된다.

#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	int T;

	string num[10] = { "ZRO", "ONE", "TWO", "THR", "FOR", "FIV", "SIX", "SVN", "EGT", "NIN" };

	cin >> T;

	for (test_case = 1; test_case <= T; ++test_case)
	{
		string temp; cin >> temp;
		int N; cin >> N;

        string in;
		vector<int> cnt(10, 0);
        for (int j = 0; j < N; j++)
        {
            cin >> in;
            
			for(int i = 0; i < 10; i++)
				if (num[i] == in)
				{
					cnt[i]++;
					break;
				}
        }

		cout << temp << '\n';
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < cnt[i]; j++)
				cout << num[i] << ' ';
		cout << '\n';
	}

	return 0;
}

'Coding_Test 연습 > SWEA' 카테고리의 다른 글

[SWEA] (C++) D3 1228 암호문1  (0) 2022.04.11
[SWEA] (C++) D3 1225 암호생성기  (0) 2022.04.11
[SWEA] (C++) D3 1220 Magnetic  (0) 2022.04.10
[SWEA] (C++) D3 1217 거듭 제곱  (0) 2022.04.10
[SWEA] (C++) D3 1216 회문2  (0) 2022.04.10

+ Recent posts