题解

378 条题解

  • 0
    @ 2017-10-01 17:53:16

    逻辑一定要严谨

    #pingpanggame.py
    resultstr = ''
    while True:
        resultstr += input()
        if 'E' in resultstr:
            break
    resultstr = resultstr[:resultstr.index('E')]
    resultstr = ''.join(list(filter(lambda c:c.isalpha(),resultstr)))
    
    wins = 0
    loss = 0
    for i in resultstr:
        if i == 'W':
            wins += 1
        elif i == 'L':
            loss += 1
        else:
            print('something wrong')
    
        if wins == 11 and (wins - loss) >= 2:
            print('{}:{}'.format(wins,loss))
            wins = 0
            loss =0
    
        elif loss == 11 and loss - wins >= 2:
            print('{}:{}'.format(wins,loss))
            wins = 0
            loss =0
    
        elif wins >= 10 and loss >= 10 and abs(wins - loss) == 2:
            print('{}:{}'.format(wins,loss))
            wins = 0
            loss =0
    
    print('{}:{}\n'.format(wins,loss))
    
    wins = 0
    loss = 0
    for i in resultstr:
        if i == 'W':
            wins += 1
        elif i == 'L':
            loss += 1
        else:
            print('something wrong')
    
        if wins == 21 and (wins - loss) >= 2:
            print('{}:{}'.format(wins,loss))
            wins = 0
            loss =0
    
        elif loss == 21 and (loss - wins) >= 2:
            print('{}:{}'.format(wins,loss))
            wins = 0
            loss =0
            
        elif wins >= 20 and loss >= 20 and abs(wins - loss) == 2:
            print('{}:{}'.format(wins,loss))
            wins = 0
            loss =0
    
    print('{}:{}'.format(wins,loss),end = '')
    
    
  • 0
    @ 2017-08-07 11:22:23

    #include <stdio.h>
    #include <string>
    #include <iostream>
    #include <vector>
    using namespace std;
    struct Node {
    int x, y;
    }a, b;
    vector<Node>ansa,ansb;

    string tmp;

    int abs(int a)
    {
    return a > 0 ? a : -a;
    }

    bool calc()
    {
    int len = tmp.length();
    for (int i = 0; i < len; i++)
    {
    if (tmp[i] == 'E')
    {
    ansa.push_back(a);
    ansb.push_back(b);
    return true;
    }
    else if (tmp[i] == 'W')
    {
    a.x++;
    b.x++;
    }
    else if (tmp[i] == 'L')
    {
    a.y++;
    b.y++;
    }
    if (abs((a.x - a.y)) >= 2 && (a.x >= 11 || a.y >= 11))
    {
    ansa.push_back(a);
    a.x = a.y = 0;
    }
    if (abs((b.x - b.y)) >= 2 && (b.x >= 21 || b.y >= 21))
    {
    ansb.push_back(b);
    b.x = b.y = 0;
    }
    }
    return false;
    }

    int main()
    {
    while (true)
    {
    getline(cin,tmp);
    if (calc())
    {
    for (int i = 0; i < ansa.size(); i++)
    printf("%d:%d\n", ansa[i].x, ansa[i].y);
    puts("");
    for (int i = 0; i < ansb.size(); i++)
    printf("%d:%d\n", ansb[i].x, ansb[i].y);
    break;
    }
    }
    return 0;
    }

  • 0
    @ 2017-08-03 13:45:50
    #include<iostream>
    using namespace std;
    bool f[10000000]={0};
    int n=0,w=0,l=0;
    char c;
    main()
    {
        do{
            cin>>c;
            if(c=='W')
            {
                n++;
                f[n]=1;
            }
            if(c=='L')
            {
                n++;
                f[n]=0;
            }
            if(c=='E')
                break;
        }while(1);
        for(int i=1;i<=n;i++)
        {
            if(f[i]==1)
                w++;
            else
                l++;
            if((w-l>=2&&w>=11)||(l-w>=2&&l>=11))
            {
                cout<<w<<":"<<l<<endl;
                w=0;l=0;
            }
        }
        cout<<w<<":"<<l<<endl;
        w=0;l=0;
        for(int i=1;i<=n;i++)
        {
            if(f[i]==1)
                w++;
            else
                l++;
            if((w-l>=2&&w>=21)||(l-w>=2&&l>=21))
            {
                cout<<"\n"<<w<<":"<<l;
                w=0;l=0;
            }
        }
        cout<<"\n"<<w<<":"<<l;
        w=0;l=0;
        return 0;
    }
    
  • 0
    @ 2017-07-26 18:37:52

    #include <iostream>
    using namespace std;

    int main()
    {
    int i,m=0,n=0;
    char a;
    string k="";
    do{
    cin>>a;
    if(a!=' ')
    k+=a;
    }while(a!='E');
    for(i=0;i<k.size() ;i++)
    {
    if(k[i]=='W')
    m++;
    if(k[i]=='L')
    n++;
    if((m>=11 && m-n>=2) || (n>=11 && n-m>=2))
    {
    cout<<m<<":"<<n<<endl;
    m=n=0;
    }
    }
    cout<<m<<":"<<n<<endl<<endl;
    m=n=0;
    for(i=0;i<k.size() ;i++)
    {
    if(k[i]=='W')
    m++;
    if(k[i]=='L')
    n++;
    if((m>=21 && m-n>=2) || (n>=21 && n-m>=2))
    {
    cout<<m<<":"<<n<<endl;
    m=n=0;

    }
    }
    cout<<m<<":"<<n<<endl;
    return 0;
    }

  • 0
    @ 2017-07-24 23:31:27

    题目不难,套路很深,9号点卡一会儿,没想到只是数据很多,改成longint就完事了ヾ(o◕∀◕)ノヾ

    var i,x,w,l:longint;a:array[0..10000000]of char;
    begin 
         x:=1;
        while a[x-1]<>'E' do begin
            read(a[x]);
            x:=x+1;
        end;
        x:=x-2;
        for i:= 1 to x do begin
            if a[i]='W' then w:=w+1;
            if a[i]='L' then l:=l+1;
            if ((w>=11)or(l>=11))and(abs(w-l)>=2) then begin 
                writeln(w,':',l);
                w:=0;l:=0;
            end;
        end;
        writeln(w,':',l);
        writeln;
        w:=0;l:=0;
        for i:= 1 to x do begin
            if a[i]='W' then w:=w+1;
            if a[i]='L' then l:=l+1;
            if ((w>=21)or(l>=21))and(abs(w-l)>=2) then begin 
                writeln(w,':',l);
                w:=0;l:=0;
            end;
        end;
        writeln(w,':',l);
    end.
    
  • 0
    @ 2017-07-10 17:10:13

    PASCAL 太简单了!!!
    type data=record
    win,lost:longint;
    end;
    var
    a:string;
    match_21,match_11:array[1..maxint*10]of data;
    i,t1,t2,j:longint;
    begin
    t1:=1;
    t2:=1;
    fillchar(a,sizeof(a),0);
    fillchar(match_11,sizeof(match_11),0);
    fillchar(match_21,sizeof(match_21),0);
    repeat
    readln(a);
    for i:=1 to length(a) do
    begin
    if a[i]<>'E' then begin
    if a[i]='W' then begin inc(match_11[t1].win);
    inc(match_21[t2].win);
    end
    else begin inc(match_11[t1].lost);
    inc(match_21[t2].lost);
    end;
    end
    else break;
    if (((match_11[t1].win-match_11[t1].lost>=2)or
    (match_11[t1].lost-match_11[t1].win>=2))and
    ((match_11[t1].lost>=11)or(match_11[t1].win>=11)))
    then inc(t1);
    if (((match_21[t2].win-match_21[t2].lost>=2)or
    (match_21[t2].lost-match_21[t2].win>=2))and
    ((match_21[t2].lost>=21)or(match_21[t2].win>=21)))
    then inc(t2);
    end;
    until pos('E',a)<>0;
    for i:=1 to t1 do
    writeln(match_11[i].win,':',match_11[i].lost);
    writeln;
    for i:=1 to t2 do
    writeln(match_21[i].win,':',match_21[i].lost);
    end.****

  • 0
    @ 2017-06-23 21:21:45

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<stdlib.h>
    using namespace std;

    int main()
    {
    char list[100000];
    int i=0,j=0,k=0,w11=0,l11=0,w21=0,l21=0,cap=-1;
    //freopen("Pingpong.in","r",stdin);
    //freopen("Pingpong.out","w",stdout);
    do
    {
    scanf("%c",&list[i]);
    cap++;
    }while(list[i++]!='E');
    i=0;
    for(i=0;i<cap;i++)
    {
    if(list[i]=='E')
    {
    break;
    }
    if(list[i]=='W')
    {
    w11++;
    }
    if(list[i]=='L')
    {
    l11++;
    }
    if(((w11>=11)&&(w11-l11>=2))||((l11>=11)&&(l11-w11>=2)))
    {
    printf("%d:%d\n",w11,l11);
    w11=0;
    l11=0;
    }
    }
    printf("%d:%d\n",w11,l11);
    printf("\n");
    for(i=0;i<cap;i++)
    {
    if(list[i]=='E')
    {
    break;
    }
    if(list[i]=='W')
    {
    w21++;
    }
    if(list[i]=='L')
    {
    l21++;
    }
    if(((w21>=21)&&(w21-l21>=2))||((l21>=21)&&(l21-w21>=2)))
    {
    printf("%d:%d\n",w21,l21);
    w21=0;
    l21=0;
    }
    }
    printf("%d:%d\n",w21,l21);
    //fclose(stdin);
    //fclose(stdout);
    return 0;
    }

  • 0
    @ 2017-06-23 21:21:22

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<stdlib.h>
    using namespace std;

    int main()
    {
    char list[100000];
    int i=0,j=0,k=0,w11=0,l11=0,w21=0,l21=0,cap=-1;
    //freopen("Pingpong.in","r",stdin);
    //freopen("Pingpong.out","w",stdout);
    do
    {
    scanf("%c",&list[i]);
    cap++;
    }while(list[i++]!='E');
    i=0;
    for(i=0;i<cap;i++)
    {
    if(list[i]=='E')
    {
    break;
    }
    if(list[i]=='W')
    {
    w11++;
    }
    if(list[i]=='L')
    {
    l11++;
    }
    if(((w11>=11)&&(w11-l11>=2))||((l11>=11)&&(l11-w11>=2)))
    {
    printf("%d:%d\n",w11,l11);
    w11=0;
    l11=0;
    }
    }
    printf("%d:%d\n",w11,l11);
    printf("\n");
    for(i=0;i<cap;i++)
    {
    if(list[i]=='E')
    {
    break;
    }
    if(list[i]=='W')
    {
    w21++;
    }
    if(list[i]=='L')
    {
    l21++;
    }
    if(((w21>=21)&&(w21-l21>=2))||((l21>=21)&&(l21-w21>=2)))
    {
    printf("%d:%d\n",w21,l21);
    w21=0;
    l21=0;
    }
    }
    printf("%d:%d\n",w21,l21);
    //fclose(stdin);
    //fclose(stdout);
    return 0;
    }

  • 0
    @ 2017-06-06 21:20:02
    #include <bits/stdc++.h>
    using namespace std;
    char letter[100000];
    int main() {
        int k=0;
        while ((letter[k]=getchar())!=EOF) 
        {
            if (letter[k] == 'E')
                break;
            k++;
        }
        int w = 0, l = 0;
        for (int i = 0; i < k; i++) {
            if (letter[i] == 'W')
                w++;
            if (letter[i] == 'L')
                l++;
            if (((w == 11||l==11)&&(abs(l-w)>=2))||((w>11||l>11)&&(abs(l-w)==2)) ){
                cout << w << ':' << l;
                w=0,l=0;
                cout << endl;
            }
        }
        cout << w << ':' << l;
        cout << endl<<endl;
         w = 0; l = 0;
        for (int i = 0; i < k; i++) {
            if (letter[i] == 'W')
                w++;
            if (letter[i] == 'L')
                l++;
            if (((w == 21||l==21)&&(abs(l-w)>=2))||((w>21||l>21)&&(abs(l-w)==2)) ){
                cout << w << ':' << l;
                w = 0, l = 0;
                cout << endl;
            }
        }
        cout<<w<<':'<<l;
        return 0;
    }
    
    
  • 0
    @ 2017-06-06 21:19:32
    #include <bits/stdc++.h>
    using namespace std;
    char letter[100000];
    int main() {
        int k=0;
        while ((letter[k]=getchar())!=EOF) 
        {
            if (letter[k] == 'E')
                break;
            k++;
        }
        int w = 0, l = 0;
        for (int i = 0; i < k; i++) {
            if (letter[i] == 'W')
                w++;
            if (letter[i] == 'L')
                l++;
            if (((w == 11||l==11)&&(abs(l-w)>=2))||((w>11||l>11)&&(abs(l-w)==2)) ){
                cout << w << ':' << l;
                w=0,l=0;
                cout << endl;
            }
        }
        cout << w << ':' << l;
        cout << endl<<endl;
         w = 0; l = 0;
        for (int i = 0; i < k; i++) {
            if (letter[i] == 'W')
                w++;
            if (letter[i] == 'L')
                l++;
            if (((w == 21||l==21)&&(abs(l-w)>=2))||((w>21||l>21)&&(abs(l-w)==2)) ){
                cout << w << ':' << l;
                w = 0, l = 0;
                cout << endl;
            }
        }
        cout<<w<<':'<<l;
        return 0;
    }
    
    
  • 0
    @ 2017-06-06 21:16:45

    #include <bits/stdc++.h>
    using namespace std;
    char letter[100000];
    int main() {
    int k=0;
    while ((letter[k]=getchar())!=EOF)
    {
    if (letter[k] == 'E')
    break;
    k++;
    }
    int w = 0, l = 0;
    for (int i = 0; i < k; i++) {
    if (letter[i] == 'W')
    w++;
    if (letter[i] == 'L')
    l++;
    if (((w == 11||l==11)&&(abs(l-w)>=2))||((w>11||l>11)&&(abs(l-w)==2)) ){
    cout << w << ':' << l;
    w=0,l=0;
    cout << endl;
    }
    }
    cout << w << ':' << l;
    cout << endl<<endl;
    w = 0; l = 0;
    for (int i = 0; i < k; i++) {
    if (letter[i] == 'W')
    w++;
    if (letter[i] == 'L')
    l++;
    if (((w == 21||l==21)&&(abs(l-w)>=2))||((w>21||l>21)&&(abs(l-w)==2)) ){
    cout << w << ':' << l;
    w = 0, l = 0;
    cout << endl;
    }
    }
    cout<<w<<':'<<l;
    return 0;
    }

  • 0
    @ 2017-06-05 22:14:14

    #include <bits/stdc++.h>
    using namespace std;
    char letter[100000];
    int main() {
    int k=0;
    while ((letter[k]=getchar())!=EOF)
    {
    if (letter[k] == 'E')
    break;
    k++;
    }
    int w = 0, l = 0;
    for (int i = 0; i < k; i++) {
    if (letter[i] == 'W')
    w++;
    if (letter[i] == 'L')
    l++;
    if (((w == 11||l==11)&&(abs(l-w)>=2))||((w>11||l>11)&&(abs(l-w)==2)) ){
    cout << w << ':' << l;
    w=0,l=0;
    cout << endl;
    }
    }
    cout << w << ':' << l;
    cout << endl<<endl;
    w = 0; l = 0;
    for (int i = 0; i < k; i++) {
    if (letter[i] == 'W')
    w++;
    if (letter[i] == 'L')
    l++;
    if (((w == 21||l==21)&&(abs(l-w)>=2))||((w>21||l>21)&&(abs(l-w)==2)) ){
    cout << w << ':' << l;
    w = 0, l = 0;
    cout << endl;
    }
    }
    cout<<w<<':'<<l;
    return 0;
    }

  • 0
    @ 2017-06-02 14:23:07
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    char info[25];
    char result_ele[5000][50];
    char result_twe[5000][50];
    int  index_ele = 0;
    int  index_twe = 0;
    int w_score = 0, l_score = 0;
    int w_score_twe = 0, l_score_twe = 0;
    void judge_based_info(int pos)
    {
        if (info[pos] == 'W')
        {
            w_score++;
            w_score_twe++;
        }
        else if (info[pos] == 'L')
        {
            l_score++;
            l_score_twe++;
        }
    }
    int main()
    {
        //freopen("data.in", "r", stdin);
        int i = 0;
    
        while (gets(info) != NULL)
        {
            for (i = 0; i < strlen(info); i++)
            {
                if (info[i] == 'E')
                {
                    sprintf(result_ele[index_ele++], "%d:%d", w_score, l_score);
                    sprintf(result_twe[index_twe++], "%d:%d", w_score_twe, l_score_twe);
                    break;
                }
                judge_based_info(i);
                if (w_score >= 11 || l_score >= 11)
                {
                    if (abs(w_score - l_score) >= 2)
                    {
                        sprintf(result_ele[index_ele++], "%d:%d", w_score, l_score);
                        w_score = 0; l_score = 0;
                    }
                }
                if (w_score_twe >= 21 || l_score_twe >= 21)
                {
                    if (abs(w_score_twe - l_score_twe) >= 2)
                    {
                        sprintf(result_twe[index_twe++], "%d:%d", w_score_twe, l_score_twe);
                        w_score_twe = 0; l_score_twe = 0;
                    }
                }
    
            }
    
        }
        for (i = 0; i < index_ele; i++)
        {
            printf("%s\n", result_ele[i]);
        }
        printf("\n");
        for (i = 0; i < index_twe; i++)
        {
            printf("%s\n", result_twe[i]);
        }
    
        return 0;
    }
    
  • 0
    @ 2017-05-26 21:12:35

    这道题重点是怎么处理输入

    #include<iostream>
    #include<string>
    
    std::string getInput();
    void compute11(std::string str);
    void compute21(std::string str);
    
    int main()
    {
        using namespace std;
    
        string str = getInput();
        compute11(str);
        cout << endl;
        compute21(str);
    
        return 0;
    }
    
    std::string getInput()
    {
        std::string temp, result;
        while(getline(std::cin, temp))
        {
            if(temp.find('E') == std::string::npos)
            {
                result.append(temp);
            }else
            {
                result.append(temp.substr(0, temp.find('E') + 1));
                break;
            }
        }
    
        return result;
    }
    
    void compute11(std::string str)
    {
        int w = 0, l = 0, i = 0;
        for(;i < (int)str.length();i++)
        {
            if(str[i] == 'W')
            {
                w++;
            }
            if(str[i] == 'L')
            {
                l++;
            }
            if(w >= 11 || l >= 11){
                if(w - l >= 2)
                {
                    std::cout << w << ":" << l << std::endl;
                    w = 0;
                    l = 0;
                }
                if(w - l <= -2)
                {
                    std::cout << w << ":" << l << std::endl;
                    w = 0;
                    l = 0;
                }
            }
            if(str[i] == 'E')
            {
                std::cout << w << ":" << l << std::endl;
            }
        }
    }
    
    void compute21(std::string str)
    {
        int w = 0, l = 0, i = 0;
        for(;i < (int)str.length();i++)
        {
            if(str[i] == 'W')
            {
                w++;
            }
            if(str[i] == 'L')
            {
                l++;
            }
            if(w >= 21 || l >= 21){
                if(w - l >= 2)
                {
                    std::cout << w << ":" << l << std::endl;
                    w = 0;
                    l = 0;
                }
                if(w - l <= -2)
                {
                    std::cout << w << ":" << l << std::endl;
                    w = 0;
                    l = 0;
                }
            }
            if(str[i] == 'E')
            {
                std::cout << w << ":" << l << std::endl;
            }
        }
    }
    
    
  • 0
    @ 2017-05-16 22:08:58

    我有一句闲的蛋疼不知当讲不当讲,数组长度设置为1000对4个,10000对8个,50000才全对,我只想问一句:有必要测这么多数么?

    #include <iostream>

    using namespace std;

    int main()
    {
    int i=0;
    char s,str[50000];
    while(true)
    {
    cin>>s;
    if(s==' ') continue;
    str[i]=s;
    if(s=='E') break;
    i+=1;
    }
    i=0;
    //11分制
    int x=0,y=0;
    while(true)
    {
    if(str[i]=='W') x+=1;
    if(str[i]=='L') y+=1;
    if(str[i]=='E')
    {
    cout<<x<<':'<<y<<endl<<endl;
    break;
    }
    if((x>=11||y>=11)&&((x-y)>=2||(y-x)>=2))
    {
    cout<<x<<':'<<y<<endl;
    x=0;y=0;
    }
    i+=1;
    }
    i=0;
    //21分制
    x=0,y=0;
    while(true)
    {
    if(str[i]=='W') x+=1;
    if(str[i]=='L') y+=1;
    if(str[i]=='E')
    {
    cout<<x<<':'<<y;
    break;
    }
    if((x>=21||y>=21)&&((x-y)>=2||(y-x)>=2))
    {
    cout<<x<<':'<<y<<endl;
    x=0;y=0;
    }
    i+=1;
    }
    return 0;
    }

  • 0
    @ 2017-05-06 17:45:11

    #include <iostream>
    #include <cstdio>
    #include <string.h>
    #include <cmath>
    using namespace std;
    const int maxn = 100010;
    char d[maxn];
    int main(){
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    char c;
    int a1,a2,b1,b2;
    a1 = a2 = b1 = b2 = 0;
    int i = 0;
    while(scanf("%c",&c)!=EOF&&c!='E'){
    d[i++] = c;
    if(c=='W'){
    a1++;
    }else if(c=='L'){
    b1++;
    }
    if((a1==11&&b1<10)||(a1>11&&a1-b1>1)||(b1==11&&a1<10)||(b1>11&&b1-a1>1)){
    printf("%d:%d\n",a1,b1);
    a1 = b1 = 0;
    }
    }
    printf("%d:%d\n",a1,b1);
    printf("\n");
    // cout<<i<<endl;
    for(int j=0;j<i;j++){
    c = d[j];
    if(c=='W'){
    a2++;
    }else if(c=='L'){
    b2++;
    }
    if((a2==21&&b2<20)||(a2>21&&a2-b2>1)||(b2==21&&a2<20)||(b2>21&&b2-a2>1)){
    printf("%d:%d\n",a2,b2);
    a2 = b2 = 0;
    }
    }
    printf("%d:%d\n",a2,b2);
    return 0;
    }

  • 0
    @ 2017-04-23 18:52:44
    #include<stdio.h>
    int main()
    {
        int _11WinCount = 0, _11LoseCount = 0, _21WinCount = 0, _21LoseCount = 0;
        char counts[100001];
        int i = 0;
        //输入所有记录
        scanf("%c", &counts[i]);
        while (counts[i] != 'E')
        {
            i++;
            scanf("%c", &counts[i]);
        }
        counts[i] = '\0';
        // 11分制下的输出
        for (i = 0; counts[i]; i++)
        {
            if (counts[i] == 'W')
                _11WinCount++;
            else if (counts[i] == 'L')
                _11LoseCount++;
            if (_11WinCount >= 11 && (_11WinCount - _11LoseCount >= 2) || _11LoseCount >= 11 && (_11LoseCount - _11WinCount >= 2))
            {
                printf("%d:%d\n", _11WinCount, _11LoseCount);
                _11WinCount = _11LoseCount = 0;
            }
        }
        printf("%d:%d\n\n", _11WinCount, _11LoseCount);
        // 21分制下的输出
        _11WinCount = _11LoseCount = 0;
        for (i = 0; counts[i]; i++)
        {
            if (counts[i] == 'W')
                _11WinCount++;
            else if (counts[i] == 'L')
                _11LoseCount++;
            if (_11WinCount >= 21 && (_11WinCount - _11LoseCount >= 2) || _11LoseCount >= 21 && (_11LoseCount - _11WinCount >= 2))
            {
                printf("%d:%d\n", _11WinCount, _11LoseCount);
                _11WinCount = _11LoseCount = 0;
            }
        }
        printf("%d:%d", _11WinCount, _11LoseCount);
        getchar();
        getchar();
        return 0;
    }
    

    很暴力

  • 0
    @ 2017-04-23 15:44:39

    C
    c
    #include<stdio.h>
    #include<stdlib.h>
    char vs[100000];
    int main()
    {
    int a=0;
    int b=0;
    int i=0;
    do
    {
    scanf("%c",&vs[i]);
    i++;
    }while(vs[i-1]!='E');
    for(int o=0;o<i-1;o++)
    {
    if(vs[o]=='W')
    {
    a++;
    }
    if(vs[o]=='L')
    {
    b++;
    }
    if((a==11||b==11)&&abs(a-b)>=2)
    {
    printf("%d:%d\n",a,b);
    a=0;
    b=0;
    }
    if(a>=10&&b>=10)
    {
    while(abs(a-b)>=2)
    {
    printf("%d:%d\n",a,b);
    a=0;
    b=0;
    }
    }
    }
    //if((a!=0||b!=0)||(vs[0]=='E'))
    {
    printf("%d:%d\n",a,b);
    a=0;
    b=0;
    }
    printf("\n");
    for(int o=0;o<i-1;o++)
    {
    if(vs[o]=='W')
    {
    a++;
    }
    if(vs[o]=='L')
    {
    b++;
    }
    if((a==21||b==21)&&abs(a-b)>=2)
    {
    printf("%d:%d\n",a,b);
    a=0;
    b=0;
    }
    if(a>=20&&b>=20)
    {
    while(abs(a-b)>=2)
    {
    printf("%d:%d\n",a,b);
    a=0;
    b=0;
    }
    }
    }
    // if((a!=0||b!=0)||(vs[0]=='E'))
    {
    printf("%d:%d\n",a,b);
    }
    return 0;
    }

  • 0
    @ 2017-04-21 16:28:08

    一开始发现第一个数据过不了,原来是当输入为E时应该输出零,一开始没注意...
    ```c++
    #include<cstdio>
    #include<string>
    #include<iostream>
    #include<cmath>
    using namespace std;

    int main(){
    ios::sync_with_stdio(false);
    string s;
    while(1){
    char c;
    cin >> c;
    if(c == 'E')break;
    s += c;
    }
    int p1 = 0,p2 = 0;
    for(int i = 0; i < s.size();i++){
    if(s[i] == 'W')p1++;
    else p2++;
    if(abs(p1-p2) >= 2 && (p1 >= 11 || p2 >= 11)){
    cout << p1<<":"<<p2<<endl;
    p1 = p2 = 0;
    }

    }
    cout << p1 << ":"<<p2<<endl;
    cout << endl;
    p1 = p2 = 0;
    for(int i = 0; i < s.size();i++){
    if(s[i] == 'W')p1++;
    else p2++;
    if(abs(p1-p2) >= 2 && (p1 >= 21 || p2 >= 21)){
    cout << p1<<":"<<p2<<endl;
    p1 = p2 = 0;
    }
    }
    cout << p1 << ":"<<p2<<endl;
    return 0;
    }
    ```

  • 0
    @ 2017-04-07 19:03:20

    m,n表示当前两个人11分制的分数
    m1,n1表示当前两个人21分制的分数
    a,a1两个数组存放第t局11分制的比分
    b,b1两个数组存放第t1局21分制的比分
    t,t1表示两种数据的局数
    达到条件就存放比分,局数+1,输入到E就break
    最后一并输出

    #include <iostream>
    #include <cstdio>
    using namespace std;
    int c;
    int m,n,i;
    int m1,n1;
    int a[10000000];
    int a1[10000000];
    int b[10000000];
    int b1[10000000];
    int t,t1;
    int main()
    {
    m=0;n=0;m1=0;n1=0;
    t=1;
    t1=1;
    while((c=getchar())!=EOF)
    {
    if (c=='W')
    { ++m;++m1;}
    if (c=='L')
    { ++n;++n1;}
    if (c=='E')
    {
    a[t]=m;
    a1[t]=n;
    b[t1]=m1;
    b1[t1]=n1;
    break;
    }
    if (m==11&&m-n>=2)
    {
    a[t]=m;
    m=0;
    a1[t]=n;
    n=0;
    t++;
    }
    else if (m>11&&m-n>=2)
    {
    a[t]=m;
    m=0;
    a1[t]=n;
    n=0;
    t++;
    }
    else if (n==11&&n-m>=2)
    {
    a[t]=m;
    m=0;
    a1[t]=n;
    n=0;
    t++;
    }
    else if (n>11&&n-m>=2)
    {
    a[t]=m;
    m=0;
    a1[t]=n;
    n=0;
    t++;
    }
    if(m1==21&&m1-n1>=2)
    {
    b[t1]=m1;
    b1[t1]=n1;
    m1=0;
    n1=0;
    t1++;
    }
    else if(m1>21&&m1-n1>=2)
    {
    b[t1]=m1;
    b1[t1]=n1;
    m1=0;
    n1=0;
    t1++;
    }
    else if(n1>21&&n1-m1>=2)
    {
    b[t1]=m1;
    b1[t1]=n1;
    m1=0;
    n1=0;
    t1++;
    }
    else if(n1==21&&n1-m1>=2)
    {
    b[t1]=m1;
    b1[t1]=n1;
    m1=0;
    n1=0;
    t1++;
    }
    }
    for(i=1;i<=t;i++)
    cout<<a[i]<<":"<<a1[i]<<endl;
    cout<<endl;
    for(i=1;i<=t1;i++)
    cout<<b[i]<<":"<<b1[i]<<endl;
    return 0;
    }
    

信息

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