MC_dream_tsr @ 2024-08-22 16:47:40
不求AC代码,求改,代码应该不算复杂 a表示第一个人的分数,b是第二个人的,函数判断是否超过两分(不会绝对值函数,
# 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 MC_dream_tsr @ 2024-08-23 12:40:14
@szrgjxms 谢谢,过了,不对啊,我也没特判啊,你能看下我源代码告诉我为啥吗?
by szrgjxms @ 2024-08-23 14:24:30
@MC_dream_tsr 最后一个数据是有点问题的,第一场结束后有个 0:0 的第二场很奇怪。你的程序有个标志(那个 x ),刚好特判到了。
by MC_dream_tsr @ 2024-08-23 14:32:36
@szrgjxms 6,谢谢