Algorithm/문자열 처리
Baekjoon 9536 여우는 어떻게 울지?
GirlFriend_Yerin
2019. 8. 23. 13:00
Link https://www.acmicpc.net/problem/9536
소스결과 2124 KB / 0 ms
출처 Baekjoon
언어 C++ 17
분류 문자열 처리
설명
숨겨진 여우의 울음소리를 찾아라
이 문제는 개인적으로 자바로 풀면 쉬울 듯 하다.
문제 난이도에 비해 입출력 때문인지 정답률이 낮다.
알고리즘
1. 첫 라인의 모든 값을 입력 받아 토큰화하여 벡터에 저장한다.
2. 동물 울음소를 입력받아 토큰화 시켜 저장한다.
3. 비교해서 일치하지 않는 울음소리를 출력한다.
소스코드
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int tcc; cin >> tcc;
cin.ignore();
while (tcc--) {
string total;
vector<string> says;
vector<string> totalSay;
getline(cin, total);
string temp = "";
for (int pT = 0; total[pT] != '\0'; pT++) {
if (total[pT] == ' ') {
totalSay.push_back(temp);
temp = "";
}
else
temp += total[pT];
}
totalSay.push_back(temp);
string input; getline(cin, input);
while (input != "what does the fox say?") {
string say = input.substr(input.find("goes ") + 5);
says.push_back(say);
getline(cin, input);
}
for (string say : totalSay) {
bool checker = true;
for (string check : says) {
if (check == say) {
checker = false;
break;
}
}
if (checker)
cout << say << ' ';
}
cout << '\n';
}
return 0;
}