全红,大佬们帮我改一下

P1042 [NOIP2003 普及组] 乒乓球

haue_202410414402 @ 2024-11-17 13:02:27

list1 = []
s = ""
while True:
    tmp = input()
    s += tmp
    if 'E' in tmp:
        break
for i in s:
    list1.append(i)
a = list1.index('E')
list1 = list1[:a]
n = len(list1)
w = 0
l = 0
for i in list1:
    if i == 'W':
        w += 1
        n -= 1
    elif i =='L':
        l += 1
        n -= 1
    if abs(w-l)>=2 and (w >= 11 or l >= 11):
        print(w,':',l,sep="")
        w = 0
        l = 0
    elif n + w + l < 11 and n == 0:
        print(w,':',l,sep="")
        break
print()
w = 0
l = 0
n = len(list1)
for j in list1:
    if j == 'W':
        w += 1
        n -= 1
    elif j == 'L':
        l += 1
        n -= 1
    if abs(w-l)>=2 and (w >= 21 or l >= 21):
        print(w,':',l,sep="")
        w = 0
        l = 0
    elif n + w +l < 21 and n == 0:
        print(w,':',l,sep="")
        break

by AK47N @ 2024-11-17 13:21:17

@haue_202410414402 点关注!

#include <iostream>
#include <cstring>
using namespace std;
int win[62503]; 
int w,l;
int main()
{
    char s;
    for(int i=1;cin>>s&&s!='E';i++)//循环读入,当读到字符E结束 
    {
        if(s=='W')win[i]=1; 
        else win[i]=2; 
    }
    //----------------11分制 ----------------
    for(int i=1;1;i++)
    {
        if(win[i]==1)w++;//胜场+1 
        if(win[i]==2)l++;//负场+1 
        if(win[i]==0)//读到0则记录结束,输出记录结束前的分数。 
        {
            cout<<w<<":"<<l<<endl<<endl;
            break;
        }
        if(w-l>=2||l-w>=2)
            if(w>=11||l>=11)//当双方比分相差大于2且一方分数大等于11输出 
            {
                cout<<w<<":"<<l<<endl;
                w=0;//比分清零 
                l=0;
            }
    }
    w=0;//清零,为21分制计算做准备 
    l=0;
    //----------------21分制 ----------------
    for(int i=1;1;i++)//一切同上,唯一区别就是判定从11变为21 
    {
        if(win[i]==1)w++;
        if(win[i]==2)l++;
        if(win[i]==0)
        {
            cout<<w<<":"<<l;
            break;
        }
        if(w-l>=2||l-w>=2)
            if(w>=21||l>=21)//11变为21 
            {
                cout<<w<<":"<<l<<endl;
                w=0;
                l=0;
            }
    }
    return 0;//华丽地结束  ㄟ(▔▽▔)ㄏ
}

by haue_202410414402 @ 2024-11-19 15:40:01

@AK47N 大佬你好,我这个是python写的,可以在我的代码上面修改吗,拜托拜托


by AK47N @ 2024-12-14 12:08:38

@haue_202410414402 OK了

s = ""
while True:
    s += input().strip()
    if "E" in s:
        s = s[:s.find("E")+1]
        break

w, l = 0, 0
for i in s:
    if i=="W":
        w+=1
    if i=="L":
        l+=1
    if i=="E":
        print("%d:%d" % (w, l))
    if w-l >= 2 or l - w >= 2:
        if w >= 11 or l >=11:
            print("%d:%d" % (w, l))
            w, l = 0, 0
w, l = 0, 0
print()
for i in s:
    if i=="W":
        w+=1
    if i=="L":
        l+=1
    if i=="E":
        print("%d:%d" % (w, l))
    if w-l >= 2 or l - w >= 2:
        if w >= 21 or l >=21:
            print("%d:%d" % (w, l))
            w, l = 0, 0

by AK47N @ 2024-12-14 12:09:35

最近有点忙


|