题解

378 条题解

  • 0
    @ 2006-10-04 14:41:04

    刚开始没有考虑到分差大于等于2时才算赢,结果只拿了50分。

    后来加上这一步之后就AC了!

  • 0
    @ 2006-10-02 22:11:23

    小弟有问题,在算完11制时,已经把输入读到尾了,有什么语句可以重新指向头,然后算21制?

  • 0
    @ 2006-09-27 18:22:30

    注意3点

    1. 一般情况下 首先达到11分或者21分的会赢

    2. 达到11分或21分后, 必须比对手多两分这局才算赢 不然一直比下去。

    3. Puppy的服务器没有任何问题 和对于Fish等服务器有的时候第7组数据会出现答案错误 莫名其妙。

  • 0
    @ 2006-09-25 12:27:22

    一定要把数组开到十万啊(我只开1000,过4个,开100000后就AC了)^-^

  • 0
    @ 2006-09-24 15:09:02

    郁闷...评测机差距好大啊.....当评测机是Vivid Puppy的时候.我通过了.其他的评测机我都90分,第6个超时...!!!

  • 0
    @ 2006-09-23 10:32:00

    跳楼……看楼下的题解时搞得我心惊肉跳的,我刚学信息的时候做的就是这题……也是一边就过……

    char c;

    long a[25000][2],b[25000][2],i,l1,l2;

    我就用了这点变量一遍过了……

  • 0
    @ 2006-09-18 14:20:08

    不边读边做也可以,分享一下我的算法。

    先开1个s数组(string),再依次读行,如果全部是空格就删掉,然后将所有字符串并到大字符串st(ansistring)里,并用o(length(st))的时间去掉所有多于空格,剩下的就很简单了~

  • 0
    @ 2006-09-11 19:57:40

    其实就是边读边做,将结果记录到一个数组里,最后统一输出(别忘了输出当前比分,包括Star_Gym大牛提醒的0:0)。我这样做一次就A了。

  • 0
    @ 2006-09-09 16:35:47

    To xrara:

    大概是你数组开小了......第六个数据是五万个'W'........

    ma数组起码要开到2500..............

    P.S.我终于懂了!@!

    必须要边读边写11的那组才能过.....

    偶试了n次读完再写,无数次的unaccepted....

    还有,第十个数据11:0之后,应该要有0:0...这个比较..晕..

  • 0
    @ 2006-09-04 20:26:03

    数组改成10万就行了~~~(还不行就改成100万)~~~呵呵

  • 0
    @ 2006-09-03 21:54:49

    当两人的比分之差小于等于1,且其中一人达到21或11时,比赛不算结束,

    直到比分之差大于1为止!

  • -1
    @ 2021-05-19 09:38:56
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    /**
     * @author wpx
     * @version V1.0
     * @Package com.algorithm
     * @date 2021/5/18 14:05
     */
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
            StringBuilder builder = new StringBuilder();
            while(true){
                final String oneLine = sc.nextLine();
                int endPos = oneLine.indexOf("E");
                if(endPos != -1){
                    // 表明有结束符
                    builder.append(oneLine.substring(0, endPos).replaceAll("\\s", ""));
                    break;
                } else {
                    builder.append(oneLine.replaceAll("\\s", ""));
                }
            }
            String str = builder.toString();
            int wNum = 0;
            int lNum = 0;
            List<String> resultOne = new ArrayList<>();
            for(int i = 0; i < str.length(); i++){
                String winner = String.valueOf(str.charAt(i));
                if(winner.equals("W")){
                    wNum++;
                } else {
                    lNum++;
                }
                // 判断是否已经有胜负
                if(wNum >= 11 || lNum >= 11) {
                    // 判断是否存在加赛的情况
                    if(wNum >= 10 && lNum >= 10) {
                        // 判断比分差异是否大于2
                        if(wNum - lNum == 2 || wNum - lNum == -2){
                             resultOne.add(wNum + ":" + lNum);
                            lNum = 0;
                            wNum = 0;
                        }
                    } else {
                         resultOne.add(wNum + ":" + lNum);
                        lNum = 0;
                        wNum = 0;
                    }
                }
            }
            resultOne.add(wNum + ":" + lNum);
            lNum = 0;
            wNum = 0;
            List<String> resultTwo = new ArrayList<>();
            for(int i = 0; i < str.length(); i++){
                String winner = String.valueOf(str.charAt(i));
                if(winner.equals("W")){
                    wNum++;
                } else {
                    lNum++;
                }
                // 判断是否已经有胜负
                if(wNum >= 21 || lNum >= 21) {
                    // 判断是否存在加赛的情况
                    if(wNum >= 20 && lNum >= 20) {
                        // 判断比分差异是否大于2
                        if(wNum - lNum == 2 ||  wNum - lNum == -2){
                            resultTwo.add(wNum + ":" + lNum);
                            lNum = 0;
                            wNum = 0;
                        }
                    } else {
                        resultTwo.add(wNum + ":" + lNum);
                        lNum = 0;
                        wNum = 0;
                    }
                }
            }
            resultTwo.add(wNum + ":" + lNum);
            for(String tmpObj : resultOne){
                System.out.println(tmpObj);
            }
            System.out.println();
            for(String tmpObj : resultTwo){
                System.out.println(tmpObj);
            }
        }
    }
    
    
  • -1
    @ 2020-12-22 22:36:46

    0:0的属实坑爹

    match = []
    list1 = []
    s = 0
    w = 0
    l = 0
    
    while True:
        list1 = list(input())
        for i in list1:
            if i != 'E':
                match.append(i)
            else:
                s = 1
                break
        if s == 1:
            break
    
    for i in match:
        if i == 'W':
            w+=1
        if i == 'L':
            l+=1
        if (w >= 11 or l >= 11) and (w - l >= 2 or l - w >= 2):
            print('{:.0f}:{:.0f}'.format(w,l))
            w = 0
            l = 0
            continue
    
    if w > 0 or l > 0:
        print('{:.0f}:{:.0f}'.format(w,l))
    if w == 0 and l == 0:
        print("0:0")
    print()
    w = 0
    l = 0
    
    for i in match:
        if i == 'W':
            w+=1
        if i == 'L':
            l+=1
        if (w >= 21 or l >= 21) and (w - l >= 2 or l - w >= 2):
            print('{:.0f}:{:.0f}'.format(w,l))
            w = 0
            l = 0
            continue
    
    if w > 0 or l > 0:
        print('{:.0f}:{:.0f}'.format(w,l),end=' ')
    if w == 0 and l == 0:
        print("0:0",end=' ')
    
  • -1
    @ 2020-07-17 09:56:02

    用python关键要注意,print是默认回车的!
    坑了我1h啊这个问题
    用print("23333", end='')可以取消默认会车

    Str = ''
    while 1:
        a = input()
        if 'E' in a:
            Str+=a.split("E")[0]
            break
        else: Str+=a
            
    #11分
    nW=0;nL=0
    for i in Str:
        if i == 'W':
            nW+=1
        else: nL+=1
        
        if (nW>=11 or nL>=11) and abs(nW-nL)>=2:
            print("%s:%s\n" % (nW,nL))
            nW=0;nL=0
    print("%s:%s\n" % (nW,nL))
    
    print('\n')
    
    #21分
    nW=0;nL=0
    for i in Str:
        if i == 'W':
            nW+=1
        else: nL+=1
        
        if (nW>=21 or nL>=21) and abs(nW-nL)>=2:
            print("%s:%s\n" % (nW,nL))
            nW=0;nL=0
                    
    print("%s:%s" % (nW,nL), end='')
    
    
  • -1
    @ 2019-08-01 19:39:49

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char s[100000]={0},c;
    int i=0,W=0,L=0,x=0,y=0,cnt;
    scanf("%c",&c);
    while(c!='E')
    {
    s[i++]=c;
    if(c=='W')W++;
    else if (c=='L')L++;
    if((W-L>=2&&W>=11)||(L-W>=2&&L>=11))
    {
    printf("%d:%d\n",W,L);
    L=0,W=0;
    }
    scanf("%c",&c);
    }
    printf("%d:%d\n\n",W,L);
    for(cnt=0;cnt<i;cnt++)
    {
    if(s[cnt]=='W')x++;
    else if (s[cnt]=='L')y++;
    if((x-y>=2&&x>=21)||(y-x>=2&&y>=21))
    {
    printf("%d:%d\n",x,y);
    x=0,y=0;

    }
    }
    printf("%d:%d\n\n",x,y);
    return 0;
    }

  • -1
    @ 2019-08-01 19:39:37

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char s[100000]={0},c;
    int i=0,W=0,L=0,x=0,y=0,cnt;
    scanf("%c",&c);
    while(c!='E')
    {
    s[i++]=c;
    if(c=='W')W++;
    else if (c=='L')L++;
    if((W-L>=2&&W>=11)||(L-W>=2&&L>=11))
    {
    printf("%d:%d\n",W,L);
    L=0,W=0;
    }
    scanf("%c",&c);
    }
    printf("%d:%d\n\n",W,L);
    for(cnt=0;cnt<i;cnt++)
    {
    if(s[cnt]=='W')x++;
    else if (s[cnt]=='L')y++;
    if((x-y>=2&&x>=21)||(y-x>=2&&y>=21))
    {
    printf("%d:%d\n",x,y);
    x=0,y=0;

    }
    }
    printf("%d:%d\n\n",x,y);
    return 0;
    }

  • -1
    @ 2019-07-24 16:49:00

    #include <iostream>
    using namespace std;
    int main()
    {
    char wl;
    int sa11=0,sb11=0,sa21=0,sb21=0,s21[1000000][2],i;
    for(i=0;i<1000000;i++) {s21[i][0]=0;s21[i][1]=0;}
    i=0;
    do
    {
    cin>>wl;
    if(wl=='W') {sa11++;sa21++;}
    else if(wl=='L') {sb11++;sb21++;}
    if((sa11>=11&&sa11-sb11>=2)||(sb11>=11&&sb11-sa11>=2))
    {
    cout<<sa11<<':'<<sb11<<endl;
    sa11=0;sb11=0;
    }
    if((sa21>=21&&sa21-sb21>=2)||(sb21>=21&&sb21-sa21>=2))
    {
    s21[i][0]=sa21;s21[i][1]=sb21;i++;
    sa21=0;sb21=0;
    }
    }
    while(wl!='E');
    if(s21[0][0]==0&&s21[0][1]==0&&sa21==0&&sb21==0)
    cout<<"0:0\n\n0:0";
    if(sa21!=0||sb21!=0) {s21[i][0]=sa21;s21[i][1]=sb21;}
    else i--;
    if((s21[0][0]!=0||s21[0][1]!=0)&&sa11==0&&sb11==0)
    cout<<"0:0\n";
    if(sa11!=0||sb11!=0) cout<<sa11<<':'<<sb11<<endl;
    cout<<endl;
    for(int j=0;j<=i;j++)
    cout<<s21[j][0]<<':'<<s21[j][1]<<endl;
    return 0;
    }

  • -1
    @ 2019-06-17 13:36:41

    #include <iostream>
    using namespace std;
    int main(void) {
    char A[100000];
    int left = 0, right = 0;
    int i = 0;
    while ((A[i] = getchar()) != EOF) {
    if (A[i] == 'E')break;
    ++i;
    }
    i = 0;
    while (A[i] != 'E') {
    if (A[i] == 'W')
    ++left;
    else if (A[i] == 'L')
    ++right;
    if ((left >= 11 || right >= 11) && (left - right > 1 || right - left > 1)) {
    cout << left <<':'<< right << endl;
    left = right = 0;
    }
    ++i;
    }
    cout << left << ':' << right << endl;
    cout << endl;
    left = right = i = 0;
    while (A[i] != 'E') {
    if (A[i] == 'W')
    ++left;
    else if (A[i] == 'L')
    ++right;
    if ((left >= 21 || right >= 21) && (left - right > 1 || right - left > 1)) {
    cout << left << ':' << right << endl;
    left = right = 0;
    }
    ++i;
    }
    cout << left << ':' << right;
    return 0;
    }

  • -1
    @ 2019-05-31 21:35:40
    #include <iostream>
    #include <queue>
    using namespace std;
    
    class Result
    {
    public:
        int playerA;
        int playerB;
        int max;
        Result(int max)
        {
            this->max = max;
            playerA = 0;
            playerB = 0;
        }
        void add(char c)
        {
            if (c == 'W')
            {
                playerA++;
            }
            else
            {
                playerB++;
            }
        }
        bool isEnd()
        {
            return (playerA >= max && playerA - playerB > 1) ||
                   (playerB >= max && playerB - playerA > 1);
        }
    };
    class Recorder
    {
    public:
        queue<Result> records;
        int max;
    
        Recorder(int max)
        {
            this->max = max;
        }
        void add(char c)
        {
            prepareQueue();
            records.back().add(c);
        }
    
        void prepareQueue()
        {
            if (records.empty() || records.back().isEnd())
            {
                Result r(max);
                records.push(r);
            }
        }
    };
    ostream &operator<<(ostream &os, Result &r)
    {
        os << r.playerA << ":" << r.playerB;
        return os;
    }
    ostream &operator<<(ostream &os, Recorder &r)
    {
        if (r.records.empty())
        {
            os << "0:0" << endl;
        }
        while (!r.records.empty())
        {
            os << r.records.front() << endl;
            r.records.pop();
        }
        return os;
    };
    
    int main()
    {
        Recorder r11(11);
        Recorder r21(21);
        while (true)
        {
            char c;
            cin >> c;
            if (c == 'E' )
            {
                break;
            }
            if (c == 'W' || c == 'L')
            {
                r11.add(c);
                r21.add(c);
            }
        }
    
        // bug of the quiz: if previous game ends, it expect we have one more 0:0
        r11.prepareQueue();
        r21.prepareQueue();
    
        cout << r11 << endl
             << r21;
        return 0;
    }
    
  • -1
    @ 2019-03-22 19:26:31

    #include<iostream>
    #include<string>
    #include<math.h>
    using namespace std;
    int abs(int a){
    if(a<0) a=0-a;
    return a;
    }
    int main(){
    char a[100001];
    int w,l,i;
    w=0;
    l=0;
    i=1;
    while(cin>>a[i]&&a[i]!='E'){
    i+=1;
    }
    i=i-1;
    for(int k=1;k<=i;k++){
    if(a[k]=='W') w+=1;
    if(a[k]=='L') l+=1;
    if(w>=11||l>=11){
    if(abs(w-l)>=2){
    cout<<w<<":"<<l<<endl;
    w=0;
    l=0;
    }
    }
    }

    cout<<w<<":"<<l<<endl<<endl;
    w=0;
    l=0;

    for(int k=1;k<=i;k++){
    if(a[k]=='W') w+=1;
    if(a[k]=='L') l+=1;
    if(w>=21||l>=21){
    if(abs(w-l)>=2){
    cout<<w<<":"<<l<<endl;
    w=0;
    l=0;
    }
    }
    }

    cout<<w<<":"<<l<<endl<<endl;

    }

信息

ID
1217
难度
7
分类
字符串 点击显示
标签
递交数
18717
已通过
4282
通过率
23%
被复制
33
上传者