※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 4351번 문제인 Hay Points이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/4351
4351번: Hay Points
The first line of input contains 2 positive integers: m <= 1000, the number of words in the Hay Point dictionary, and n <= 100, the number of job descriptions. m lines follow; each contains a word (a string of up to 16 lower-case letters) and a dollar valu
www.acmicpc.net
각 문자열의 점수는 map을 이용하면 쉽게 저장하고 읽어올 수 있다.
각 테스트케이스 별로 "."이 나올 때까지 문자열들을 읽으면서 map에 들어있는 문자열이라면 해당 문자열에 대응되는 점수를 더해나가 답을 구하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
map<string, ll> mp;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, T; cin >> N >> T;
while (N--) {
string s; ll val; cin >> s >> val;
mp.insert(make_pair(s, val));
}
while (T--) {
ll ans = 0;
string s; cin >> s;
while (s != ".") {
if (mp.find(s) != mp.end()) ans += mp[s];
cin >> s;
}
cout << ans << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 11735 // C++] 정산소 (0) | 2022.06.05 |
---|---|
[BOJ 5547 // C++] 일루미네이션 (0) | 2022.06.05 |
[BOJ 5545 // C++] 최고의 피자 (0) | 2022.06.05 |
[BOJ 18511 // C++] 큰 수 구성하기 (0) | 2022.06.05 |
[BOJ 5546 // C++] 파스타 (0) | 2022.06.05 |