Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

코딩로그

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

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";
		}
	}
}

[결과 화면]

'YJ > C++' 카테고리의 다른 글

[백준/BOJ/C++] 11655번 ROT13  (0) 2021.12.22
[백준/BOJ/C++] 7595번 Triangles  (0) 2021.12.22
[백준/BOJ/C++] 4714번 Lunacy  (0) 2021.12.22
[백준/BOJ/C++] 13772번 Holes  (0) 2021.12.22
[백준/BOJ/C++] 14182번 Tax  (0) 2021.12.22