poj2993 与2996相反的模拟

#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
struct data {
       int r,l;
       char ch;
}chess[65];
string s;
char ch,ch1,ch2;
int tot,p,w;
bool cmp(data a,data b) {
     if (a.r>b.r) return true;
     else if (a.r==b.r && a.l<b.l) return true;
     return false;
}
int main() {
    tot = 0;
    cin >> s;
    scanf("%c",&ch);
    while (scanf("%c",&ch) && ch!='\n') {
          if (ch<97 && ch!=',') {
                     scanf("%c%c",&ch1,&ch2);
                     tot++;
                     chess[tot].ch = ch;
                     chess[tot].r = ch2-48;
                     chess[tot].l = ch1-96;
          }
          else if (ch!=',') {
                  scanf("%c",&ch1);
                  tot++;
                  chess[tot].ch = 'P';
                  chess[tot].r = ch1-48;
                  chess[tot].l = ch-96;
          }
    }
    cin >> s;
    scanf("%c",&ch);
    while (scanf("%c",&ch) && ch!='\n') {
          if (ch<97 && ch!=',') {
                     scanf("%c%c",&ch1,&ch2);
                     tot++;
                     chess[tot].ch = ch+32;
                     chess[tot].r = ch2-48;
                     chess[tot].l = ch1-96;
          }
          else if (ch!=',') {
                  scanf("%c",&ch1);
                  tot++;
                  chess[tot].ch = 'p';
                  chess[tot].r = ch1-48;
                  chess[tot].l = ch-96;
          }
    }
    sort(chess+1,chess+1+tot,cmp);
    p = 1;
    printf("+---+---+---+---+---+---+---+---+\n");
    for (int i=1;i<=8;i++) {
        for (int k=1;k<=8;k++) {
            if ((i+k)%2==0) w = 0;
            else w = 1;
            printf("|");
            if (w) printf(":"); else printf(".");
            if (chess[p].r==9-i && chess[p].l==k) {
                                printf("%c",chess[p].ch);
                                p++;
            }
            else if (w) printf(":"); else printf(".");
            if (w) printf(":"); else printf(".");
        }
        printf("|\n+---+---+---+---+---+---+---+---+\n");
    }
    return 0;
}

你可能感兴趣的:(c,String,include)