[문제]
27160번: 할리갈리 (acmicpc.net)
27160번: 할리갈리
한별이가 종을 쳐야 하면 YES을, 아니면 NO를 출력해주세요.
www.acmicpc.net
[문제 풀이]
map을 이용해서 string에 저장되어있는 값이 5인지를 확인했다.
[회고]
map에서 iterator 사용법이 순간 기억이 안나서 단순 구현을 했지만 iterator 순회법도 기억해두자.
[코드]
#include <iostream>
#include <map>
using namespace std;
int main(){
int n;
cin>>n;
map<string,int> mp;
for(int i = 0;i<n;i++){
string s;
int a;
cin>>s>>a;
mp[s] += a;
}
bool answer = false;
if(mp["STRAWBERRY"] == 5){
answer = true;
}
else if(mp["BANANA"] == 5){
answer = true;
}
else if(mp["LIME"] ==5){
answer = true;
}
else if(mp["PLUM"] == 5){
answer = true;
}
cout<< (answer ? "YES" : "NO")<<endl;
return 0;
}