본문 바로가기

Algorithm

(C++) - 백준(BOJ) 9946번 : 단어 퍼즐 답

반응형

Strcmp(const *char,const *char): 두 문자열이 같은지 다른지를 비교해주는 함수입니다.

1.헤더는 <string.h><cstring>이 필요합니다.2.문자열이 같다면 0을 반환하고 다르다면 -1 또는 1을 반환해줍니다.
 
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
    int as, bs;
    int i = 1;
    while (1)
    {
        char a[1001], b[1001];
        cin >> a >> b;
        if (!strcmp(a, "END") && !strcmp(b, "END")) { break; }
        as = strlen(a);
        bs = strlen(b);
        if (as != bs)
            cout << "Case " << i++ << ": different" <<'\n';
        else
        {
            sort(a, a + as);
            sort(b, b + bs);
            if(!strcmp(a,b))
                cout << "Case " << i++ << ": same" << '\n';
            else
                cout << "Case " << i++ << ": different" << '\n';
        }
    }
}