본문 바로가기

USACO/Bronze

백준 14174 Block Game (USACO December 2016 Bronze 2번)

문제 링크: https://www.acmicpc.net/problem/14174

 

14174번: Block Game

Farmer John is trying to teach his cows to read by giving them a set of N spelling boards typically used with preschoolers (1≤N≤100). Each board has a word and an image on each side. For example, one side might have the word 'cat' along with a picture of a

www.acmicpc.net

각 카드마다 앞면, 뒷면 모두를 표현하기 위해 필요한 알파벳 갯수를 세서 다 더함.

예시 >

2

aaa aab

bba aba

첫번째 카드에서는 3장의 a와 1장의 b가 필요하고

두번째 카드에서는 2장의 a와 2장의 b가 필요하므로

총 5장의 a와 3장의 b가 있으면 됨.

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
#include <bits/stdc++.h>
using namespace std;
 
int N, ans[200], tmp1[200], tmp2[200];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> N;
    while(N--) {
        memset(tmp1, 0sizeof(tmp1));
        memset(tmp2, 0sizeof(tmp2));
        string s, t;
        cin >> s >> t;
        for(int j = 0; j < s.size(); j++)
            tmp1[s[j]]++;
        for(int j = 0; j < t.size(); j++)
            tmp2[t[j]]++;
        for(int j = 'a'; j <= 'z'; j++)
            ans[j] += max(tmp1[j], tmp2[j]);
    }
 
    for(int i = 'a'; i <= 'z'; i++)
        cout << ans[i] << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter