Submission

Status:

PPPPPP-PPPPP-P----PP

Subtask/Task Score:

70/100

Score: 70

User: theem1502

Problemset: Othello

Language: c

Time: 0.002 second

Submitted On: 2025-09-25 17:24:24

#include <stdio.h>
#include <stdlib.h>

int main() {

    char thearray[8][8];
    for (int i = 0; i < 8; i++) {
        char tempstring[9];
        scanf("%s", tempstring);
        for (int j = 0; j < 8; j++) {
            thearray[i][j] = tempstring[j];
        }
    }


    for (int i = 0; i < 10000; i++) {
        int currentx = 0, currenty = 0;
        scanf("%d %d", &currentx, &currenty);

        if (currentx == -1 && currenty == -1) {
            break;
        }

        char opposite;
        int currentchar;
        if (i % 2 == 0) {
        thearray[currentx][currenty] = 'B';
        opposite = 'W';
        currentchar = 'B';
        }
        else {
            thearray[currentx][currenty] = 'W';
        opposite = 'B';
        currentchar = 'W';
        }




        int checked = 0;
        if (thearray[currentx-1][currenty] == opposite) {
            int thecount = 0;
            int check = 0;
            for (int j = 1; j <= 7; j++) {
                if (currentx - j < 0 ) {
                    break;
                }
                int currentcoordinates = thearray[currentx-j][currenty];
                
                if (currentcoordinates == opposite) {
                    thecount++;
                    continue;
                }
                else if (currentcoordinates == '_') {
                    break;
                }
                else if (currentcoordinates == currentchar) {
                    check = 1;
                    break;
                }
                
                }
                if (check == 1) {
                    for (int j = 1; j <= thecount; j++) {
                        thearray[currentx-j][currenty] = currentchar;
                    }
                }
            
        }
        if (thearray[currentx-1][currenty+1] == opposite) {
            int thecount = 0;
            int check = 0;
            for (int j = 1; j <= 7; j++) {
                if (currentx - j < 0 || currenty + j > 7) {
                    break;
                }
                int currentcoordinates = thearray[currentx-j][currenty+j];
                if (currentcoordinates == opposite) {
                    thecount++;
                    continue;
                }
                else if (currentcoordinates == '_') {
                    break;
                }
                else if (currentcoordinates == currentchar) {
                    check = 1;
                    break;
                }
                
                }
                if (check == 1) {
                    for (int j = 1; j <= thecount; j++) {
                        thearray[currentx-j][currenty+j] = currentchar;
                    }
                }
        }
        if (thearray[currentx-1][currenty-1] == opposite) {
            int thecount = 0;
            int check = 0;
            for (int j = 1; j <= 7; j++) {
                if (currentx - j < 0 || currenty - j < 0) {
                    break;
                }
                int currentcoordinates = thearray[currentx-j][currenty-j];
                if (currentcoordinates == opposite) {
                    thecount++;
                    continue;
                }
                else if (currentcoordinates == '_') {
                    break;
                }
                else if (currentcoordinates == currentchar) {
                    check = 1;
                    break;
                }
                
                }
                if (check == 1) {
                    for (int j = 1; j <= thecount; j++) {
                        thearray[currentx-j][currenty-j] = currentchar;
                    }
                }
        }
        if (thearray[currentx][currenty+1] == opposite) {

            int thecount = 0;
            int check = 0;
            for (int j = 1; j <= 7; j++) {
                if (currenty + j > 7) {
                    break;
                }
                int currentcoordinates = thearray[currentx][currenty+j];
                if (currentcoordinates == opposite) {
                    thecount++;
                    continue;
                }
                else if (currentcoordinates == '_') {
                    break;
                }
                else if (currentcoordinates == currentchar) {
                    check = 1;
                    break;
                }
                
                }
                if (check == 1) {
                    for (int j = 1; j <= thecount; j++) {
                        thearray[currentx][currenty+j] = currentchar;
                    }
                }
        }
        if (thearray[currentx][currenty-1] == opposite) {
            int check = 0;
            int thecount = 0;
            for (int j = 1; j <= 7; j++) {
            if (currenty - j < 0) {
                    break;
                }
                int currentcoordinates = thearray[currentx][currenty-j];
                if (currentcoordinates == opposite) {
                    thecount++;
                    continue;
                }
                else if (currentcoordinates == '_') {
                    break;
                }
                else if (currentcoordinates == currentchar) {
                    check = 1;
                    break;
                }
                
                }
                if (check == 1) {
                    for (int j = 1; j <= thecount; j++) {
                        thearray[currentx][currenty-j] = currentchar;
                    }
                }
        }
        if (thearray[currentx+1][currenty] == opposite) {
            int thecount = 0;
            int check = 0;
            for (int j = 1; j <= 7; j++) {
                if (currentx + j > 7) {
                    break;
                }
                int currentcoordinates = thearray[currentx+j][currenty];
                if (currentcoordinates == opposite) {
                    thecount++;
                    continue;
                }
                else if (currentcoordinates == '_') {
                    break;
                }
                else if (currentcoordinates == currentchar) {
                    check = 1;
                    break;
                }
                
                }
                if (check == 1) {
                    for (int j = 1; j <= thecount; j++) {
                        thearray[currentx+j][currenty] = currentchar;
                    }
                }
        }
        if (thearray[currentx+1][currenty-1] == opposite) {
            int thecount = 0;
            int check = 0;
            for (int j = 1; j <= 7; j++) {
                if (currentx + j > 7 || currenty - j < 0) {
                    break;
                }
                int currentcoordinates = thearray[currentx+j][currenty-j];
                if (currentcoordinates == opposite) {
                    thecount++;
                    continue;
                }
                else if (currentcoordinates == '_') {
                    break;
                }
                else if (currentcoordinates == currentchar) {
                    check = 1;
                    break;
                }
                
                }
                if (check == 1) {
                    for (int j = 1; j <= thecount; j++) {
                        thearray[currentx+j][currenty-j] = currentchar;
                    }
                }
        }
        if (thearray[currentx+1][currenty+1] == opposite) {
            int thecount = 0;
            int check = 0;
            for (int j = 1; j <= 7; j++) {
                if (currentx + j > 7 || currenty + j > 7) {
                    break;
                }
                int currentcoordinates = thearray[currentx+j][currenty+j];
                if (currentcoordinates == opposite) {
                    thecount++;
                    continue;
                }
                else if (currentcoordinates == '_') {
                    break;
                }
                else if (currentcoordinates == currentchar) {
                    check = 1;
                    break;
                }
                
                }
                if (check == 1) {
                    for (int j = 1; j <= thecount; j++) {
                        thearray[currentx+j][currenty+j] = currentchar;
                    }
                }
        }

        int tempsum = 0;
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if (thearray[i][j] != '_') {
                    tempsum++;
                }
            }
        }
        if (tempsum == 64) {
            break;
    }


        

    }


    for (int i = 0; i < 8; i ++) {
        for (int j = 0; j < 8; j++) {
            printf("%c", thearray[i][j]);
        }
        printf("\n");
    }


    int whitecount = 0;
    int blackcount = 0;
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
        if (thearray[i][j] == 'B') {
            blackcount++;
        }
        else if(thearray[i][j] == 'W') {
            whitecount++;
        }
    }
    }
    if (blackcount == whitecount) {
        printf("%s", "draw");
    }
    else if (blackcount > whitecount) {
        printf("%s","black wins");
    }
    else {
        printf("%s", "white wins");
    }
}