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 dream_dad @ 2024-08-22 16:51:06
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
string s[100001];
int a[100001],b[100001],a2[100001],b2[100001];
bool check(int x)
{
int t=s[x].size();
for(int i=0;i<t;i++)
if(s[x][i]=='E')return 0;
return 1;
}
int main()
{
int n=1,i,j,t=1,t2=1;
cin>>s[n];
while(check(n))
{
n++;
cin>>s[n];
}
for(i=1;i<=n;i++)
{
int sz=s[i].size();
for(j=0;j<sz;j++)
{
if(s[i][j]=='E')
{
for(i=1;i<=t;i++)
cout<<a[i]<<":"<<b[i]<<endl;
cout<<endl;
for(i=1;i<=t2;i++)
cout<<a2[i]<<":"<<b2[i]<<endl;
return 0;
}
if(s[i][j]=='W')
a[t]++,a2[t2]++;
else if(s[i][j]=='L')
b[t]++,b2[t2]++;
if((a[t]>=11||b[t]>=11)&&abs(a[t]-b[t])>=2)
{
t++;
}
if((a2[t2]>=21||b2[t2]>=21)&&abs(a2[t2]-b2[t2])>=2)
{
t2++;
}
}
}
return 0;
}
by BlackWuKong @ 2024-08-22 16:52:38
#include<bits/stdc++.h>
using namespace std;
int f[2]={11,21};
int a[25*2500+10],n=0;
int main(){
char tmp;
while (1){
cin>>tmp;
if (tmp=='E') break;
else if (tmp=='W') a[n++]=1;
else if (tmp=='L') a[n++]=0;
}
for (int i=0;i<2;i++){
int w=0,l=0;
for (int j=0;j<n;j++){
w+=a[j],l+=1-a[j];
if (max(l,w)>=f[i]&&abs(w-l)>=2){
cout<<w<<":"<<l<<endl;
w=l=0;
}
}
cout<<w<<":"<<l<<endl;
cout<<endl;
}
return 0;
}
求关@MC_dream_tsr
by MC_dream_tsr @ 2024-08-22 16:55:04
@lanlingxuan 已关(壶关行吗?
by BlackWuKong @ 2024-08-22 16:55:58
@MC_dream_tsr 已关
by szrgjxms @ 2024-08-22 16:56:52
程序应该忽略 E 之后的所有内容。你在输入的时候应该是存在点问题的
by MC_dream_tsr @ 2024-08-22 16:56:53
e.....没有大佬改改我这抽象的代码吗?
by I_AM_joker @ 2024-08-22 16:58:10
给你写个abs吧
abs()
by szrgjxms @ 2024-08-22 16:58:38
最后一轮输出的时候也要特判,如果 a, b 都为 0 就不用输出了
by I_AM_joker @ 2024-08-22 16:59:01
@I_AM_joker 对不起没补充完整
绝对值:abs(a-b)
by szrgjxms @ 2024-08-22 17:11:11
# include<bits/stdc++.h>
using namespace std;
int a, b;
bool a_b(int x, int y) {
if(abs(x - y) >= 2)
return true;
else
return false;
}
void C() {
cout << a << ":" << b << endl;
}
char s1;
string s;
int main() {
while(1) {
cin >> s1;
if(s1 == 'E') break;
s += s1;
}
a = b = 0;
bool flag=0;
for(int i = 0; i < s.length() ; i++) {
if(s[i] == 'W') a++;
if(s[i] == 'L') b++;
if(a >= 11 || b >= 11) {
if(a_b(a, b)) {
C();
a = 0, b = 0;
flag = 1;
}
}
}
if(flag == 0 || a != 0 || b != 0)
C();
cout << endl;
a = 0, b = 0;
flag = 0;
for(int i = 0; i < s.length() ; i++) {
if(s[i] == 'W') a++;
if(s[i] == 'L') b++;
if(a >= 21 || b >= 21) {
if(a_b(a, b)) {
C();
a = 0, b = 0;
flag = 1;
}
}
}
if(flag == 0 || a != 0 || b != 0)
C();
return 0;
}
90分了,最后一个点有点问题,要特判,翻翻讨论区就有了