[백준/C++] 9946 - 단어 퍼즐

orangesnail·2025년 8월 15일

백준

목록 보기
141/169

https://www.acmicpc.net/problem/9946


구현하기

아스키코드를 이용해서 배열에 저장해줘야 한다!

#include <iostream>
#include <string>
using namespace std;

int main() {
    int caseNum = 1;
    while (true) {
        string word, abc;
        cin >> word;
        cin >> abc;

        if (word == "END" && abc == "END") break;

        int count1[26] = {0};
        for (char c : word) count1[c - 'a']++;

        int count2[26] = {0};
        for (char c : abc) count2[c - 'a']++;

        string answer = "same";
        for (int i = 0; i < 26; i++) {
            if (count1[i] != count2[i]) {
                answer = "different";
                break;
            }
        }
        cout << "Case " << caseNum++ << ": " << answer << endl;
    }
    return 0;
}
profile
초보입니다. 피드백 환영합니다 😗

0개의 댓글