문제 풀이/문제 풀이(BOJ)
[Silver V] 콰트로치즈피자 - 27964
풀뿌리
2024. 9. 17. 00:00
[문제 위치]
https://www.acmicpc.net/problem/27964
[문제 풀이]
문자열 관련한 간단한 문제이다.
집합을 사용하면 보다 쉽게 풀 수 있다.
문자열이 Cheese로 마무리 되는지를 확인 한 다음 집합에 삽입한다. 집합은 중복되는 것을 하나로 처리하므로 집합의 갯수가 4개를 넘는지 여부만 확인해주면 콰트로치즈피자의 여부를 도출 할 수 있다.
#include <iostream>
#include <string>
#include <set>
using namespace std;
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main() {
fastio;
int n;
cin >> n;
set<string> cheeses;
for (int i = 0; i < n; ++i) {
string topping;
cin >> topping;
if (topping.size() >= 6 && topping.substr(topping.size() - 6) == "Cheese") {
cheeses.insert(topping);
}
}
if (cheeses.size() >= 4) {
cout << "yummy" << endl;
}
else {
cout << "sad" << endl;
}
return 0;
}