题目
https://www.luogu.com.cn/problem/P1042
题目分析
直到分差大于或者等于2,才一局结束:意思就是即使有人先得了1分,但是两人分差<2也不算结束,要继续比赛,直到分差大于或者等于2才这局结束
代码
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #include<vector> using namespace std; typedef pair<int, int> p; vector<p>list; int main() { char tmp; int a=0, b=0; int a2 = 0, b2 = 0; int count1a = 0,count1b=0,count2a=0, count2b = 0; while (1) { scanf("%c", &tmp); if (tmp == 'E') { printf("%d:%d ", a, b); p temp = make_pair(a2, b2); list.push_back(temp); break; } if (tmp == 'W') { a++; a2++; count1a++; count2a++; } if (tmp == 'L') { b++; b2++; count1b++; count2b++; } if (abs(a - b) >= 2 && (count1a >= 11||count1b>=11)) { printf("%d:%d ", a, b); a = 0; b = 0; count1a = 0; count1b = 0; } if (abs(a2 - b2) >= 2 && (count2a >= 21 || count2b >= 21)) { p temp = make_pair(a2, b2); list.push_back(temp); a2 = 0; b2 = 0; count2a = 0; count2b = 0; } } printf(" "); for (int i = 0; i < list.size();i++) printf("%d:%d ", list[i].first, list[i].second); }