poj2993 poj2669
扯淡题。
2993
#include <iostream> #include <stdio.h> #include <string> #include <stdlib.h> using namespace std; char map[10][10]; int main() { string waste1, s1, s2,waste2; cin>>waste1; bool fla=true; if (waste1 == "White:") { cin >> s1 >> waste2 >> s2; } else { cin >> s2 >> waste2 >> s1; } for (int k = 0; k <= s1.size(); k++) { if (s1[k] == ',' || (k == s1.size())) { if (k == 3)//three characters { map[7 - s1[k - 1] + '1'][s1[k - 2] - 'a'] = toupper(s1[k - 3]); } else if (k == 2) { map[7 - s1[k - 1] + '1'][s1[k - 2] - 'a'] = 'P'; } else { if (s1[k - 4] == ',') { map[7 - s1[k - 1] + '1'][s1[k - 2] - 'a'] = toupper(s1[k - 3]); } else { map[7 - s1[k - 1] + '1'][s1[k - 2] - 'a'] = 'P'; } } } } for (int k = 0; k <= s2.size(); k++) { if (s2[k] == ','||(k==s2.size())) { if (k == 3)//three characters { map[7 - s2[k - 1] + '1'][s2[k - 2] - 'a'] = tolower(s2[k - 3]); } else if (k == 2) { map[7 - s2[k - 1] + '1'][s2[k - 2] - 'a'] = 'p'; } else { if (s2[k - 4] == ',') { map[7 - s2[k - 1] + '1'][s2[k - 2] - 'a'] = tolower(s2[k - 3]); } else { map[7 - s2[k - 1] + '1'][s2[k - 2] - 'a'] = 'p'; } } } } for (int i = 0; i < 8; i++) { cout<<"+---+---+---+---+---+---+---+---+"<<endl; for (int j = 0; j < 8; j++) { if(fla) { cout<<"|."; if((map[i][j]<='a'||map[i][j]>='z')&&(map[i][j]<='A'||map[i][j]>='Z')) { cout<<".."; } else { cout << map[i][j]<<'.'; } } else { cout<<"|:"; if((map[i][j]<='a'||map[i][j]>='z')&&(map[i][j]<='A'||map[i][j]>='Z')) { cout<<"::"; } else { cout << map[i][j]<<':'; } } fla=!fla; ///cout << map[i][j] << ' '; } cout <<'|'<< endl; fla=!fla; } cout<<"+---+---+---+---+---+---+---+---+"<<endl; }
poj2996
#include <iostream> #include <stdlib.h> #include <iostream> #include <string> #include <stdio.h> using namespace std; bool flag = true; char map[10][10]; void findupper(char c) { for (int i = 8; i >= 1; i--) { for (int j = 1; j <= 8; j++) { if (map[i][j] == c) { if (flag) { flag = false; } else{ cout << ','; } if (c != 'P' && c != 'p') cout << (char) toupper(c); cout << (char) (j + 'a' - 1) << 9 - i; } } } } void findlower(char c) { for (int i = 1; i <= 8; i++) { for (int j = 1; j <= 8; j++) { if (map[i][j] == c) { if (flag) { flag = false; } else{ cout << ','; } if (c != 'P' && c != 'p') cout << (char) toupper(c); cout << (char) (j + 'a' - 1) << 9 - i; } } } } int main() { memset(map, ' ', sizeof(map)); string waste; getline(cin, waste); for (int i = 1; i <= 8; i++) { string s; getline(cin, s); for (int j = 1; j <= 8; j++) { if (isalpha(s[4 * j - 2])) { map[i][j] = s[4 * j - 2]; } } getline(cin, waste); } /*for (int i = 1; i <= 8; i++) { for (int j = 1; j <= 8; j++) { cout << map[i][j] << ' '; } cout << endl; }*/ flag = true; cout << "White: "; findupper('K'); findupper('Q'); findupper('R'); findupper('B'); findupper('N'); findupper('P'); cout << endl << "Black: "; flag = true; findlower('k'); findlower('q'); findlower('r'); findlower('b'); findlower('n'); findlower('p'); cout << endl; //system("pause"); }