Untitled

 avatar
unknown
plain_text
11 days ago
1.4 kB
11
Indexable
#include <stdio.h>
#include <ctype.h>

int coordenada_para_indices(char *coord, int *linha, int *coluna) {
    if (coord[0] < 'a' || coord[0] > 'z') return 1;
    if (coord[1] < '0' || coord[1] > '9') return 1;

    *coluna = coord[0] - 'a';
    *linha = coord[1] - '1';

    return 0;
}


int main() {
    char comando;
    char argumento[100];
    char tabuleiro[5][5] = {
        {'e', 'c', 'a', 'd', 'c'},
        {'d', 'c', 'd', 'e', 'c'},
        {'b', 'd', 'd', 'c', 'e'},
        {'c', 'd', 'e', 'e', 'b'},
        {'a', 'c', 'c', 'b', 'b'}
    };

    while (1) {
        comando = '\0';
        argumento[0] = '\0';
        int linha;
        int coluna;
        for(int i = 0; i < 5; i++){
            for(int j = 0; j < 5; j++){
                printf("%c ", tabuleiro[i][j]);
            }
            printf("\n");
        }

        if(scanf(" %c", &comando) != 1) return 1;

        if (comando == 'b') {
            
            if(scanf(" %s", argumento) != 1) return 1;
            coordenada_para_indices(argumento, &linha, &coluna);
            tabuleiro[linha][coluna] = toupper(tabuleiro[linha][coluna]);
        }

        if (comando == 'r') {
            if(scanf(" %s", argumento) != 1) return 1;
            coordenada_para_indices(argumento, &linha, &coluna);
            tabuleiro[linha][coluna] = '#';
        }
    }
}
Editor is loading...
Leave a Comment