- 乒乓球
- 2018-02-23 09:57:44 @
我遇到最神奇的情况了
蒟蒻代码
#include<bits/stdc++.h>
using namespace std;
class Pair {
public:
int W,L;
Pair(int x,int y) {
W=x,L=y;
}
};
queue<Pair>Eleven;
queue<Pair>Twelve;
int main(int argc,char** argv) {
register char Win;
register int W11(0),L11(W11),W21(W11),L21(W11);
while(cin>>Win) {
if(Win=='E')break;
switch(Win) {
case 'W':
++W11;
if(W11>=11&&W11-L11>=2) {
Pair a(W11,L11);
Eleven.push(a);
W11=L11=0;
}
++W21;
if(W21>=21&&W21-L21>=2) {
Pair a(W21,L21);
Twelve.push(a);
W21=L21=0;
}
break;
case 'L':
++L11;
if(L11>=11&&L11-W11>=2) {
Pair a(W11,L11);
Eleven.push(a);
W11=L11=0;
}
++L21;
if(L21>=21&&L21-W21>=2) {
Pair a(W21,L21);
Twelve.push(a);
W21=L21=0;
}
break;
default:
register int a(233);
}
}
if(W11||L11) {
Pair a(W11,L11);
Eleven.push(a);
}
if(W21||L21) {
Pair a(W21,L21);
Twelve.push(a);
}
while(!Eleven.empty()) {
cout<<Eleven.front().W<<":"<<Eleven.front().L<<endl;
Eleven.pop();
}
cout<<endl;
while(!Twelve.empty()) {
cout<<Twelve.front().W<<":"<<Twelve.front().L<<endl;
Twelve.pop();
}
return 0;
}
1 条评论
-
聪明的猪 (xxz) LV 6 @ 2018-03-11 16:51:41
C++实现:
#include <iostream> #include <string> using std::string; void processing(string, int); int main(void) { using std::cin; using std::cout; using std::endl; bool run; int i; string result, winAndLose; run = true; while (run) { getline(cin, winAndLose); int len = int(winAndLose.length()); if(len > 20) { len = 20; } for (i = 0; i < len; i++) { switch (winAndLose.at(i)) { case '\0': run = false; i = int(winAndLose.length()); break; case 'E': run = false; i = int(winAndLose.length()); break; case 'W': result += winAndLose.at(i); break; case 'L': result += winAndLose.at(i); break; default: break; } } } processing(result, 11); cout << endl; processing(result, 21); return 0; } void processing(string winOrLose, int winScore) { using std::cout; using std::endl; int huaWin, huaLose, i; huaLose = 0; huaWin = 0; for(i = 0; i < int(winOrLose.length()); i++) { if ('W' == winOrLose.at(i)) { huaWin++; } else if ('L' == winOrLose.at(i)) { huaLose++; } if (((huaLose >= winScore) || (huaWin >= winScore)) && ((huaLose - huaWin > 1) || (huaWin - huaLose > 1))) { cout << huaWin << ":" << huaLose << endl; huaLose = 0; huaWin = 0; } } cout << huaWin << ":" << huaLose << endl; return; }
- 1