2993:Emag eht htiw Em Pleh

keyword

C++

概要

チェスの盤面を出力する問題。
実装ゲー。「,」で分割とかはスペースに置換してstreamに流しているのをcodeforcesあたりで見かけた記憶がある。実際ポインタ使って云々とかするよりは楽だった。

int main(){

    char ans[20][50];
    int x, y;
    string line, str;

    for(int i=0; i<9; i++){
        strcpy(ans[2*i], "+---+---+---+---+---+---+---+---+");
    }
    for(int i=0; i<8; i++){
        if(i&1) strcpy(ans[1+2*i],  "|:::|...|:::|...|:::|...|:::|...|");
        else strcpy(ans[1+2*i], "|...|:::|...|:::|...|:::|...|:::|");
    }

    for(int loop = 0; loop < 2; loop++){
        getline(cin, line);
        for(int i=0; i<SZ(line); i++)if(line[i]==',') line[i] = ' ';
        stringstream ss(line);
        ss >> str;
        while(ss >> str){
            if(SZ(str)==2){
                x = str[0] - 'a';
                y = str[1] - '1';
                y = 15 - 2*y;
                x = 2 + 4*x;
                ans[y][x] = (!loop)?'P':'p';
            }
            else{
                x = str[1] - 'a';
                y = str[2] - '1';
                y = 15 - 2*y;
                x = 2 + 4*x;
                ans[y][x] = (!loop)?str[0]:(str[0] - 'A' + 'a');
            }
        }
    }

    for(int i=0; i<17; i++){
        printf("%s\n",ans[i]);
    }

    return 0;
}