标签:return lag 之间 问题 重叠 dex front find g++
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <stdlib.h> #include <cstdlib> #include <string.h> #include <string> #include <cmath> #include <map> using namespace std; #define inf 200 vector<char> a; vector<char> b; vector<char> c;//桌上的牌 char s[40]; void print() { if (a.size() != 0) for (vector<char>::iterator i = a.begin(); i < a.end(); i++) cout << *i; else for (vector<char>::iterator i = b.begin(); i < b.end(); i++) cout << *i; } int find() { for (int i = 0; i < c.size() - 1; i++) { if (c[i] == c.back()) return i; } return inf; } void add(int index, vector<char> &t) { for (int i = c.size() - 1; i >= index; i--) t.push_back(c[i]); c.erase(c.begin()+index, c.end()); } void match() { int flag = 1; while (a.size() != 0 && b.size() != 0) { if (flag % 2 == 1) {//a出牌 if (!c.empty()) { c.push_back(a.front()); a.erase(a.begin()); int t = find();//寻找重叠部分 if (t != inf) { add(t, a);//将重叠部分加入到此人手中 flag--;//下次还是这个人出牌 } } else { c.push_back(a.front());//牌局为空,直接出牌即可 a.erase(a.begin()); } } else { if (!c.empty()) { c.push_back(b.front()); b.erase(b.begin()); int t = find(); if (t != inf) { flag--; add(t, b); } } else { c.push_back(b.front()); b.erase(b.begin()); } } //print(); flag++; } } int main() { scanf("%s", s); for (int i = 0; s[i] != ‘\0‘; i++) a.push_back(s[i]); scanf("%s", s); for (int i = 0; s[i] != ‘\0‘; i++) b.push_back(s[i]); match(); print(); return 0; }
标签:return lag 之间 问题 重叠 dex front find g++
原文地址:https://www.cnblogs.com/woxiaosade/p/10465895.html