202240210230FUQIANG @ 2024-09-07 23:00:48
大佬们,我只ac了最后一个,求改
// https://ac.nowcoder.com/discuss/926597
#include <bits/stdc++.h>
using namespace std;
int a = 0, b = 0;
int hanshu1(string str)
{
int i = 0, hua = 0, dui = 0;
while (1)
{
if (str[i] == 'W')
hua++;
else
dui++;
if (hua >= 11 || dui >= 11)
{
if (hua - dui >= 2)
{
cout << hua << ':' << dui << endl;
dui = 0;
hua = 0;
a++;
}
if (dui - hua >= 2)
{
cout << hua << ':' << dui << endl;
dui = 0;
hua = 0;
b++;
}
}
i++;
if (str[i] == 'E')
{
cout << hua << ':' << dui << endl;
break;
}
}
return 0;
}
int hanshu2(string str)
{
int i = 0, hua = 0, dui = 0;
while (1)
{
if (str[i] == 'W')
hua++;
else if (str[i] == 'L')
dui++;
if (hua >= 21 || dui >= 21)
{
if (hua - dui >= 2)
{
cout << hua << ':' << dui << endl;
dui = 0;
hua = 0;
a++;
}
if (dui - hua >= 2)
{
cout << hua << ':' << dui << endl;
dui = 0;
hua = 0;
b++;
}
}
i++;
if (str[i] == 'E')
{
cout << hua << ':' << dui << endl;
break;
}
}
return 0;
}
int main()
{
char a;
string str;
int i = 0;
while (1)
{
scanf("%c", &a);
if (a == 'E')
{
str = str + 'E';
break;
}
else if (a == '\n')
;
else
{
str = str + a;
}
}
// cout << endl;
// cout << str << endl;
hanshu1(str);
cout << endl;
hanshu2(str);
// cout << a << ':' << b << endl;
return 0;
}
by luoyiwen @ 2024-09-07 23:26:07
#include<bits/stdc++.h>
using namespace std;
char a;
long long vis[20000005],h,hd,i=1;
int main()
{
while(cin>>a)
{
if(a=='E') break;
if(a=='W') vis[i]=1;
if(a=='L') vis[i]=2;
i++;
}
i=1;
while(vis[i]!=0)
{
if(vis[i]==1) h++;
if(vis[i]==2) hd++;
if(h-hd>=2||hd-h>=2)
{
if(h>=11||hd>=11) cout<<h<<':'<<hd<<"\n",h=0,hd=0;
}
i++;
}
cout<<h<<':'<<hd<<"\n\n",h=0,hd=0,i=1;
while(vis[i]!=0)
{
if(vis[i]==1) h++;
if(vis[i]==2) hd++;
if(h-hd>=2||hd-h>=2)
{
if(h>=21||hd>=21) cout<<h<<':'<<hd<<"\n",h=0,hd=0;
}
i++;
}
cout<<h<<':'<<hd<<"\n",h=0,hd=0;
return 0;
}
求关QWQ