日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj2996

發(fā)布時(shí)間:2023/12/4 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj2996 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本題是簡單的模擬,使用雙層vector嵌套存儲(chǔ)棋子的位置和種類,然后分別對每個(gè)vector進(jìn)行排序

注意:排序方法為sort(piece[i].begin(), piece[i].end(), cmpWhite);
當(dāng)然,cmpWhite是比較函數(shù),可以不加比較函數(shù),只用用前兩個(gè)參數(shù)。

?

#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <cstdlib> #include<algorithm> using namespace std;const int maxn = 9;int getid[150];struct Piece {int x, y, d;Piece(){}Piece(int xx, int yy, char dd) :x(xx), y(yy), d(dd){} };vector<vector<Piece> > piece(12);void init() {string st;memset(getid, -1, sizeof(getid));getid[int('K')] = 0;getid[int('Q')] = 1;getid[int('R')] = 2;getid[int('B')] = 3;getid[int('N')] = 4;getid[int('P')] = 5;getid[int('k')] = 6;getid[int('q')] = 7;getid[int('r')] = 8;getid[int('b')] = 9;getid[int('n')] = 10;getid[int('p')] = 11;for (int i = 1; i < maxn; i++){getline(cin, st);for (int j = 1; j < maxn; j++){char ch;getchar();getchar();cin >> ch;getchar();if (getid[int(ch)] != -1)piece[getid[int(ch)]].push_back(Piece(9 - i, j, ch));}getline(cin, st);} }bool cmpWhite(const Piece &a, const Piece &b) {if (a.x == b.x)return a.y < b.y;return a.x < b.x; }bool cmpBlack(const Piece &a, const Piece &b) {if (a.x == b.x)return a.y < b.y;return a.x > b.x; }void sortout() {for (int i = 0; i < 6; i++)sort(piece[i].begin(), piece[i].end(), cmpWhite);for (int i = 6; i < 12; i++)sort(piece[i].begin(), piece[i].end(), cmpBlack); }void output() {bool first = true;cout << "White: ";for (int i = 0; i < 6; i++){for (unsigned int j = 0; j < piece[i].size(); j++){if (first)first = false;elsecout << ",";if (piece[i][j].d != 'P')cout << char(piece[i][j].d);cout << char(piece[i][j].y + 'a' - 1) << piece[i][j].x;}}cout << endl;first = true;cout << "Black: ";for (int i = 6; i < 12; i++){for (unsigned int j = 0; j < piece[i].size(); j++){if (first)first = false;elsecout << ",";if (piece[i][j].d != 'p')cout << char(piece[i][j].d - 'a' + 'A');cout << char(piece[i][j].y + 'a' - 1) << piece[i][j].x;}} }int main() {//freopen("D:\\t.txt", "r", stdin);init();sortout();output();return 0; }

總結(jié)

以上是生活随笔為你收集整理的poj2996的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。