반응형
문제 출처 :
https://www.acmicpc.net/problem/14670
알고리즘 분석 :
문제 해결에 필요한 사항
1. Map STL :: http://www.crocus.co.kr/604
Map을 이용하면 쉽게 풀 수 있는 문제이다.
약 이름, 효능으로 맵에 저장시키고 최종적으로 필요로하는 약이 존재하는지 map을 통해 탐색하여 모두 존재하면 그 약의 효능을 출력하고, 필요로하는 약이 없다면 chk 변수를 false로 변경시켜 YOU DIED를 출력하면 된다.
소스 코드 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <iostream> #include <cstdio> #include <map> #include <vector> using namespace std; map<int, int> mp; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int a, b; scanf("%d %d", &a, &b); mp[a] = b; } scanf("%d", &n); for (int i = 0; i < n; i++) { int a; bool chk = true; vector<int> vc; scanf("%d", &a); for (int j = 0; j < a; j++) { int b; scanf("%d", &b); if (mp.count(b) != 0) vc.push_back(mp[b]); else chk = false; } if(chk) for (auto i : vc) printf("%d ", i); else printf("YOU DIED"); printf("\n"); } return 0; } // This source code Copyright belongs to Crocus // If you want to see more? click here >> | Crocus |
반응형
'Applied > 알고리즘 문제풀이' 카테고리의 다른 글
[1280번] 나무 심기 (0) | 2017.08.17 |
---|---|
[4796번] 캠핑 (0) | 2017.08.17 |
[7806번] GCD! (0) | 2017.08.12 |
[7569번] 토마토 (0) | 2017.08.12 |
[1152번] 단어의 개수 (0) | 2017.08.12 |