※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 7596번 문제인 MP3 Songs이다.

문제는 아래 링크를 확인하자.

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

 

7596번: MP3 Songs

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. 

www.acmicpc.net

주어지는 노래의 제목들에 공백이 포함될 수 있음에 유의하자.

getline 함수를 이용하면 간단히 할 수 있다.

 

아래는 제출한 소스코드이다.

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

vector<string> vec;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int T = 0;
	string s; getline(cin, s);
	int N = stoi(s);
	while (N) {
		T++; cout << T << '\n';
		vec.clear();
		while (N--) {
			getline(cin, s);
			vec.push_back(s);
		}
		sort(vec.begin(), vec.end());
		for (auto ss : vec) cout << ss << '\n';
		getline(cin, s);
		N = stoi(s);
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 24510 // C++] 시간복잡도를 배운 도도  (0) 2022.03.02
[BOJ 1431 // C++] 시리얼 번호  (0) 2022.03.01
[BOJ 1449 // C++] 수리공 항승  (0) 2022.02.27
[BOJ 11381 // C++] Sequences  (0) 2022.02.26
[BOJ 13335 // C++] 트럭  (0) 2022.02.25

+ Recent posts