fby0506 @ 2024-08-30 16:15:54
#include <iostream>
#include <cstring>
using namespace std;
string str;
int show(int n) {
int a=0,b=0;
for(char ch: str) {
if(ch=='E') {
break;
}
if(ch=='W') {
a++;
} else if(ch=='L') {
b++;
}
if(a>=n||b>=n&&abs(a-b)>=2) {
cout<<a<<':'<<b<<endl;
a=0,b=0;
}
}
cout<<a<<':'<<b<<endl;
return 0;
}
int main() {
getline(cin,str,'E');
show(11);
cout<<endl;
show(21);
return 0;
}
by dream_dad @ 2024-08-30 16:20:15
@fby0506
# include<bits/stdc++.h>
using namespace std;
int a, b, x;
bool a_b(int x, int y){
if(x > y){
if(x - y >= 2) return true;
else return false;
}
if(x < y){
if(y - x >= 2) return true;
else return false;
}
if(x == y) return false;
}
void C(){
cout << a << ":" << b << endl;
}
int main(){
string s1, s;
while(1){
cin >> s1;
s += s1;
if(s[s.length() - 1] == 'E') break;
}
for(int i = 0; i < s.length() - 1; i++){
if(s[i] == 'W') a++;
if(s[i] == 'L') b++;
if(a + b >= 11){
if(a_b(a, b)){
C();
a = 0, b = 0;
}else{
x = 1;
}
if(x == 1){
if(a_b(a, b)){
C();
x = 0, a = 0, b = 0;
}
}
}
}
C();
cout << endl;
a = 0, b = 0, x = 0;
for(int i = 0; i < s.length() - 1; i++){
if(s[i] == 'W') a++;
if(s[i] == 'L') b++;
if(a + b >= 21){
if(a_b(a, b)){
C();
a = 0, b = 0;
}else{
x = 1;
}
if(x == 1){
if(a_b(a, b)){
C();
x = 0, a = 0, b = 0;
}
}
}
}
C();
return 0;
}
by jiangyixuan_eason @ 2024-08-31 13:17:43
#include<bits/stdc++.h>
using namespace std;
char str[100010];
int cnt = 0;
void show(int n) {
int a = 0, b = 0;
for (int i = 0; i < cnt; i++) {
if (str[i] == 'W') a++;
if (str[i] == 'L') b++;
if ((a >= n || b >= n) && abs(a - b) >= 2) {
cout << a << ":" << b << endl;
a = b = 0;
}
}
cout << a << ":" << b << endl;
}
int main() {
char ss;
while (cin >> ss && ss != 'E') {
if (ss == 'W' || ss == 'L') {
str[cnt++] = ss;
}
}
show(11);
cout << endl;
show(21);
}
@fby0506