YJ/C++

[백준/BOJ/C++] 7596번 MP3 Songs

Team DAON 2021. 12. 22. 09:42

[문제]

Sue loves her mp3 player but she hates the fact that her shuffle mode plays her tracks randomly. Because she loves order and patterns she would like the tunes on her mp3 player to be played in alphabetical order. In this problem you have to help Sue by sorting her tunes into alphabetical order of tune name.

[입력]

Input consists of a number of scenarios, each beginning with a single positive integer, n, the number of music tracks that require sorting (1 < n <= 200). The last line of input is a single 0 – this scenario should not be processed.

Each scenario consists of n lines, each line containing a tune name. No line will contain more than 250 characters. Each name will begin with an alphabetic character.

[출력]

Output will consist of the scenario number, the first being 1, on a line on its own. This will be followed by n lines showing the tune names from the input list, sorted in alphabetical order, one name per line. Case should be ignored. 

[Source Code]

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	int count = 0;
	while(true){
		int num;
		cin >> num;
		cin.ignore();
		if(num == 0) break;

		string *arr = new string[num];

		for(int i = 0; i < num; i++){
			string input;
			getline(cin, input);
			arr[i] = input;
		}

		sort(arr, arr+num);
		cout << ++count << "\n";
		for(int i = 0; i < num; i++){
			cout << arr[i] << "\n";
		}
	}
}

[결과 화면]