Skip to content

Instantly share code, notes, and snippets.

@wowoto9772
Created September 30, 2016 13:45
Show Gist options
  • Save wowoto9772/9cd1f692a677d7b0c8c9de2eef268e4b to your computer and use it in GitHub Desktop.
Save wowoto9772/9cd1f692a677d7b0c8c9de2eef268e4b to your computer and use it in GitHub Desktop.

님 게임 (normal play rule)

마지막 돌을 가져가는 사람이 패배한다.

#include <stdio.h>
 
int main() {
 
    int n;
    scanf("%d", &n);
 
    int nim = 0;
 
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
 
        nim ^= x;
    }
 
    // normal play
 
    int winner = 0;
 
    if (nim) {
        // first win
        winner = 1;
    }
    else {
        winner = 2;
    }
 
    if (winner == 1) {
        printf("koosaga");
    }
    else {
        printf("cubelover");
    }
 
}

님게임 2 (misere play)

마지막 돌을 가져가는 사람이 승리한다.

#include <stdio.h>
 
int main() {
 
    int n;
    scanf("%d", &n);
 
    int nim = 0;
 
    int one = 0;
 
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
 
        nim ^= x;
 
        one += x == 1;
    }
 
    // misere play
 
    int winner = 0;
 
    if (one == n) {
        if (nim) {
            // second win
            winner = 2;
        }
        else {
            winner = 1;
        }
    }
    else {
        if (nim) {
            // first win
            winner = 1;
        }
        else {
            winner = 2;
        }
    }
 
    if (winner == 1) {
        printf("koosaga");
    }
    else {
        printf("cubelover");
    }
 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment