건전한 건전지
article thumbnail
728x90
반응형

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

 

9536번: 여우는 어떻게 울지?

각 테스트케이스마다 여우의 울음소리를 한 줄씩, 녹음된 순서대로 출력한다. 여우의 울음소리가 녹음되어 있음이 보장된다. (알려진 것과는 달리, 여우는 모스 부호로 의사소통하지 않는다.)

www.acmicpc.net

문자열 파싱 문제이다. stringstream을 이용하였다.

잘 안 쓰던거라 아래 블로그를 참고했따..

https://myprivatestudy.tistory.com/48

 

#include <bits/stdc++.h>
using namespace std;

int main() {
	int tc; cin >> tc; cin.ignore();

	while (tc--) {
		list <string> ls;

		string s;
		string tmp;

		// 전체 동물 소리 녹음
		getline(cin, s);
		stringstream ss(s);

		// list에 넣어줌
		while (ss >> tmp)
			ls.push_back(tmp);

		while (1) {
        	// 한 줄 한 줄 입력을 받아준다.
			string last;
			getline(cin, s);
			
            // what does the fox say? 가 나온다면 마지막 문장이기 때문에 종료
			if (s == "what does the fox say?")
				break;
			
            // A does B로 형식이 정해져있기 때문에 마지막 문자열만 받아왔다.
			istringstream iss(s);
			iss >> last >> last >> last;
			
            // 중복된 소리도 있기 때문에 해당 문자는 list에서 전부 삭제해준다.
			ls.remove(last);
		}
		
        // 남은 문자들을 출력하기!
		for (auto i = ls.begin(); i != ls.end(); i++)
			cout << *i << " ";
		cout << '\n';
	}

}

 

list의 remove함수를 정말 유용하게 사용한 문제였다.

 

728x90
반응형
profile

건전한 건전지

@건전한 건전지

나는 언리얼의 왕이 될 남자다 👑