출처: 2022 January Bronze Problem 1 ( link )
문제 설명
3X3 charater puzzle
- Green: correct
- Yellow: Mis location
입력 1
COW
SAY
MOO
WIN
THE
IOI
출력
1
1
입력 2
AAA
BBB
CCC
AYY
AAA
ZZZ
출력
1
2
문제 풀이
문자열 비교를 어떻게 할 것인가 하는 문제이다. 입력으로 주어진 3 x 3 퍼즐을 1 x 9 형태로 바꿔도 문제 풀이에 영향은 없다. char[9] 인 두개의 배열/vector를 만들어서 예상 답안과 실제 답안을 입력하고, 전체를 비교해서 같으면 Green 값에 반영한다. 다음은, 두 답안의 A~Z의 빈도를 확인해서, 잘못된 위치지만 있었는지 확인해서 Yellow 값에 반영한다. 다만, Green 에 반영된 결과를 두번 세지 않도록 해줘야 한다.
프로그램 내용
더보기
// serialization & count frequency
for(int i = 0; i<3; ++i)
{
string tmp;
cin >> tmp;
ans += tmp;
ans_cnt[tmp[0]-'A']++;
ans_cnt[tmp[1]-'A']++;
ans_cnt[tmp[2]-'A']++;
}
for(int i = 0; i<3; ++i)
{
string tmp;
cin >> tmp;
gus += tmp;
gus_cnt[tmp[0]-'A']++;
gus_cnt[tmp[1]-'A']++;
gus_cnt[tmp[2]-'A']++;
}
// cnt_g & cnt_y
for(int i = 0; i<9; ++i)
{
if(ans[i] == gus[i])
cnt_g++;
}
for(int i = 0; i<26; ++i)
{
cnt_y += min(ans_cnt[i],gus_cnt[i]);
}
cnt_y -= cnt_g;
'USACO' 카테고리의 다른 글
USACO 2022 January Bronze Problem 2 (0) | 2022.02.21 |
---|