题解

381 条题解

  • 0
    @ 2018-03-25 18:41:13

    建议p党练手就算了,毕竟字符串在c++里比pascal里恶心多了,思路详见代码。

    #include<bits/stdc++.h>
    using namespace std ;
    //Vijos P1217
    
    int ball ;
    string x , y ;//虽然我并不喜欢用string,但是这里的确用string更方便
    void score(int x)//一个过程记录得分,表示在x分制下的结果
    {
        int w = 0 , l = 0 ;
        for (int i = 0 ; i < y.size() ; i ++)//不知道哪里学来的一个测字符串长度的神奇函数
        {
            if (y[i] == 'W')//赢球给自己加分
                w ++ ;
            else//否则给对方加分,如题意
                l ++ ;
            if (((w >= x) || (l >= x)) && (abs(w - l) >= 2))//按照乒乓球赛的规则,若满足一方达到分数,**同时**双方比方差距在2分以上即结束比赛[https://baike.baidu.com/item/%E4%B9%92%E4%B9%93%E7%90%83/221415?fr=aladdin](http://)
            {
                cout << w << ":" << l << endl ;//输出结果
                w = 0 ;
                l = 0 ;
            }
        }
        cout << w << ":" << l << endl ;//最后有没比完的,也输出
    }
    int main()
    {
        do
        {
            cin >> x ;
            ball = x.find("E") ;//也是一个神奇的函数,类似pascal中的pos
            if (ball == -1)//在c++中,未查到返回-1
                y = y + x ;
            else
            {
                for (int i = 0 ; i < ball ; i ++)
                {
                    y = y + x[i] ;
                }
            }
        }
        while (ball == -1) ;
        score(11) ;//调用score函数
        cout << endl ;
        score(21) ;
    }
    
  • 0
    @ 2018-03-11 16:54:24

    C++实现:

    #include <iostream>
    #include <string>
    using std::string;
    void processing(string, int);
    int main(void)
    {
        using std::cin;
        using std::cout;
        using std::endl;
        bool run;
        int i;
        string result, winAndLose;
        run = true;
        while (run)
        {
            getline(cin, winAndLose);
            int len = int(winAndLose.length());
            if(len > 20) {
                len = 20;
            }
            for (i = 0; i < len; i++)
            {
                switch (winAndLose.at(i))
                {
                    case '\0':
                        run = false;
                        i = int(winAndLose.length());
                        break;
                    case 'E':
                        run = false;
                        i = int(winAndLose.length());
                        break;
                    case 'W':
                        result += winAndLose.at(i);
                        break;
                    case 'L':
                        result += winAndLose.at(i);
                        break;
                    default:
                        break;
                }
            }
        }
        processing(result, 11);
        cout << endl;
        processing(result, 21);
        return 0;
    }
    void processing(string winOrLose, int winScore)
    {
        using std::cout;
        using std::endl;
        int huaWin, huaLose, i;
        huaLose = 0;
        huaWin = 0;
        for(i = 0; i < int(winOrLose.length()); i++)
        {
            if ('W' == winOrLose.at(i))
            {
                huaWin++;
            }
            else if ('L' == winOrLose.at(i))
            {
                huaLose++;
            }
            if (((huaLose >= winScore) || (huaWin >= winScore)) && ((huaLose - huaWin > 1) || (huaWin - huaLose > 1)))
            {
                cout << huaWin << ":" << huaLose << endl;
                huaLose = 0;
                huaWin = 0;
            }
        }
        cout << huaWin << ":" << huaLose << endl;
        return;
    }
    
  • 0
    @ 2018-03-11 16:53:52

    C++实现:

    #include <iostream>
    #include <string>
    using std::string;
    void processing(string, int);
    int main(void)
    {
        using std::cin;
        using std::cout;
        using std::endl;
        bool run;
        int i;
        string result, winAndLose;
        run = true;
        while (run)
        {
            getline(cin, winAndLose);
            int len = int(winAndLose.length());
            if(len > 20) {
                len = 20;
            }
            for (i = 0; i < len; i++)
            {
                switch (winAndLose.at(i))
                {
                    case '\0':
                        run = false;
                        i = int(winAndLose.length());
                        break;
                    case 'E':
                        run = false;
                        i = int(winAndLose.length());
                        break;
                    case 'W':
                        result += winAndLose.at(i);
                        break;
                    case 'L':
                        result += winAndLose.at(i);
                        break;
                    default:
                        break;
                }
            }
        }
        processing(result, 11);
        cout << endl;
        processing(result, 21);
        return 0;
    }
    void processing(string winOrLose, int winScore)
    {
        using std::cout;
        using std::endl;
        int huaWin, huaLose, i;
        huaLose = 0;
        huaWin = 0;
        for(i = 0; i < int(winOrLose.length()); i++)
        {
            if ('W' == winOrLose.at(i))
            {
                huaWin++;
            }
            else if ('L' == winOrLose.at(i))
            {
                huaLose++;
            }
            if (((huaLose >= winScore) || (huaWin >= winScore)) && ((huaLose - huaWin > 1) || (huaWin - huaLose > 1)))
            {
                cout << huaWin << ":" << huaLose << endl;
                huaLose = 0;
                huaWin = 0;
            }
        }
        cout << huaWin << ":" << huaLose << endl;
        return;
    }
    
  • 0
    @ 2018-03-07 12:58:55

    Java 版的
    import java.io.IOException;
    import java.util.Scanner;

    public class Main {
    public static void main(String[] args) throws IOException{
    Scanner sn = new Scanner(System.in);
    String inputStr = "";
    StringBuilder sb = new StringBuilder();
    while(true){
    String temp = sn.nextLine();
    if (temp.contains("E")) {
    sb.append(temp);
    break;
    }
    sb.append(temp);
    }
    inputStr = sb.toString().substring(0,sb.toString().indexOf('E'));
    countPoints(inputStr,11);
    countPoints(inputStr,21);
    }
    public static void countPoints(String inputStr,int scoreType){
    int score1 = 0;
    int score2 = 0;
    for(int i = 0;i<inputStr.length();i++){
    if(inputStr.charAt(i) == 'W'){
    score1 ++;
    }
    if(inputStr.charAt(i) == 'L'){
    score2 ++;
    }
    if((score1 >=scoreType || score2 >= scoreType) && Math.abs(score1 -score2) >=2){
    System.out.println(score1+":"+score2);
    score1 = 0; score2 = 0;
    }
    }
    System.out.println(score1+":"+score2);
    System.out.println();
    }
    }

  • 0
    @ 2018-02-10 08:40:47
    #include<cstdio>
    
    using namespace std;
    
    int f21[10010][2];
    int main(){
        int w1=0,l1=0,w2=0,l2=0,j=0;
        char k;
        while(scanf("%c",&k)&&k!='E'){
            if(k=='W'){w1++;w2++;}
            if(k=='L'){l1++;l2++;}
            if((w1>=11&&w1-l1>=2)||(l1>=11&&l1-w1>=2)){
                printf("%d:%d\n",w1,l1);
                w1=0;l1=0;
            };
            if((w2>=21&&w2-l2>=2)||(l2>=21&&l2-w2>=2)){
                f21[j][0]=w2;
                f21[j][1]=l2;
                w2=0;l2=0;j++;
            };
        }
        printf("%d:%d\n\n",w1,l1);
        for(int i=0;i<j;i++)
            printf("%d:%d\n",f21[i][0],f21[i][1]);
        printf("%d:%d",w2,l2);
    
        return 0;
    }
    
  • 0
    @ 2018-02-08 17:09:13

    #include <stdio.h>

    int main()
    {
    char letter[1000];
    int i,j;
    int m=0,n=0;
    int an=0,bn=0;
    int a[10],b[10];
    int en=0,fn=0;
    int e[10],f[10];
    for(i=0;i<1000;i++)
    {
    scanf("%c",&letter[i]);
    if(letter[i]=='W')
    {
    an++;
    en++;
    }
    if(letter[i]=='L')
    {
    bn++;
    fn++;
    }
    if(an+bn==11)
    {
    a[m]=an;
    b[m]=bn;
    m++;
    an=0;
    bn=0;
    }
    if(en+fn==21)
    {
    e[n]=en;
    f[n]=fn;
    n++;
    en=0;
    fn=0;
    }
    if(letter[i]=='E')
    break;
    }
    if(an!=0||bn!=0)
    {
    a[m]=an;
    b[m]=bn;
    }
    if(en!=0||fn!=0)
    {
    e[n]=en;
    f[n]=fn;
    }
    for(i=0;i<=m;i++)
    printf("%d:%d\n",a[i],b[i]);
    for(i=0;i<=n;i++)
    printf("%d:%d\n",e[i],f[i]);
    }大佬这个哪里错了

  • 0
    @ 2018-01-21 14:39:43

    #include<cstdio>
    char s[1000010];
    int a=0,b=0,n=0;
    int main()
    {
    while(scanf("%c",&s[n]) && s[n]!='E')
    if(s[n]!='\n') n++;
    for(int i=0;i<n;i++)
    {
    if(s[i]=='W') a++;
    if(s[i]=='L') b++;
    if((a-b>1 || b-a>1) && (a>10 || b>10))
    {
    printf("%d:%d\n",a,b);
    a=b=0;
    }
    }
    printf("%d:%d\n",a,b);
    printf("\n");
    a=b=0;
    for(int i=0;i<n;i++)
    {
    if(s[i]=='W') a++;
    if(s[i]=='L') b++;
    if((a-b>1 || b-a>1) && (a>20 || b>20))
    {
    printf("%d:%d\n",a,b);
    a=b=0;
    }
    }
    printf("%d:%d\n",a,b);
    return 0;
    }

  • 0
    @ 2018-01-07 13:41:31

    知道比赛规则的细节
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <string.h>

    int main()
    {
    char a[100000][22];
    int i=0,j=0,w=0,l=0,n;
    while((a[i][j]=getchar())!='E')
    {
    if(a[i][j]=='\n')
    {
    i++;j=0;
    }
    else j++;
    }
    n=i;
    for(i=0;i<=n&&a[i-1][j]!='E';i++)
    {
    for(j=0;a[i][j]!='\n';j++)
    {

    if(a[i][j]=='E')
    break;
    if(a[i][j]=='W')
    w++;
    if(a[i][j]=='L')
    l++;
    if((w==11||l==11)&&abs(w-l)>=2)
    {
    printf("%d:%d\n",w,l);
    w=0;
    l=0;
    }
    if((w>=10&&l>=10)&&abs(w-l)>=2)
    {
    printf("%d:%d\n",w,l);
    w=l=0;
    }
    }
    }
    printf("%d:%d\n",w,l);
    printf("\n");
    w=l=0;
    for(i=0;i<=n&&a[i-1][j]!='E';i++)
    {
    for(j=0;a[i][j]!='\n';j++)
    {
    if(a[i][j]=='E')
    break;
    if(a[i][j]=='W')
    w++;
    if(a[i][j]=='L')
    l++;
    if((l==21||w==21)&&abs(w-l)>=2)
    {
    printf("%d:%d\n",w,l);
    w=0;
    l=0;
    }
    if((w>=20&&l>=20)&&abs(w-l)>=2)
    {
    printf("%d:%d\n",w,l);
    w=l=0;
    }

    }
    }
    printf("%d:%d",w,l);
    return 0;
    }

  • 0
    @ 2018-01-05 15:41:27

    #include<iostream>
    using namespace std;
    #include<cstring>
    char str[10000000];
    int main()
    {
    for(int i=0;;++i)
    {
    cin>>str[i];
    if(str[i]=='E') break;
    }
    int a=0,b=0,len=strlen(str);
    for(int i=0;i!=len-1;++i)
    {
    if(str[i]==' ') continue;
    if(str[i]=='W') ++a;
    else ++b;
    if((a>=11&&a-b>=2)||(b>=11&&b-a>=2)) {cout<<a<<":"<<b<<endl;a=0;b=0;}
    }
    cout<<a<<":"<<b<<endl<<endl;
    a=0;
    b=0;
    for(int i=0;i!=len-1;++i)
    {
    if(str[i]==' ') continue;
    if(str[i]=='W') ++a;
    else ++b;
    if((a>=21&&a-b>=2)||(b>=21&&b-a>=2)) {cout<<a<<":"<<b<<endl;a=0;b=0;}
    }
    cout<<a<<":"<<b<<endl;
    }

  • 0
    @ 2017-12-01 19:13:08

    #include<stdio.h>
    #include<math.h>//WWWWWWWWWWWWWWWWWWWWWWLWE
    char ch[10010];
    void outpute(int n,int type)
    {
    int i,a=0,b=0;
    for(i=0;i<n;i++)
    {

    if(ch[i]=='W') a++;
    if(ch[i]=='L') b++;
    if((a==type||b==type)&&(abs(a-b)>=2)||(abs(a-b)==2)&&((a>type)||(b>type)))
    {
    printf("%d:%d\n",a,b);
    a=0,b=0;
    }
    }
    printf("%d:%d",a,b);
    }
    int main()
    {
    int i=0;
    do//----------------------方法2
    {
    scanf("%c",&ch[i]);
    }while(ch[i++]!='E');
    /* while ((ch[i] = getchar()) != EOF) {
    if (ch[i] == 'E') break;
    i++;
    }*/
    outpute(i,11);
    printf("\n\n");
    outpute(i,21);
    return 0;
    }

  • 0
    @ 2017-11-29 22:45:26

    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <math.h>
    #include <iostream>
    using namespace std;
    int main()
    {
    int xiaohua=0;
    int enemy=0;
    string str;
    string::iterator it;
    getline(cin,str,'E');
    it=str.begin();
    if(str=="")
    {
    cout<<"0:0"<<endl;
    cout<<endl;
    cout<<"0:0"<<endl;
    }
    for(it;it!=str.end();it++)
    {
    if((xiaohua>=11||enemy>=11) && fabs(xiaohua-enemy)>=2 )
    {
    cout<<xiaohua<<":"<<enemy<<endl;
    xiaohua=0;
    enemy=0;
    }
    if(*it=='W') xiaohua++;
    if(*it=='L') enemy++;
    if((it==(str.end()-1)) && (xiaohua>=11||enemy>=11)&& fabs(xiaohua-enemy)>=2)
    {
    cout<<xiaohua<<":"<<enemy<<endl;
    cout<<"0:0"<<endl;
    continue;
    }
    if(it==(str.end()-1))
    {
    cout<<xiaohua<<":"<<enemy<<endl;
    }
    }
    cout<<endl;
    it=str.begin();
    xiaohua=0;
    enemy=0;
    for(it;it!=str.end();it++)
    {
    if((xiaohua>=21||enemy>=21) && fabs(xiaohua-enemy)>=2 )
    {
    cout<<xiaohua<<":"<<enemy<<endl;
    xiaohua=0;
    enemy=0;
    }
    if(*it=='W') xiaohua++;
    if(*it=='L') enemy++;
    if((it==(str.end()-1)) && (xiaohua>=21||enemy>=21)&& fabs(xiaohua-enemy)>=2)
    {
    cout<<xiaohua<<":"<<enemy<<endl;
    cout<<"0:0"<<endl;
    continue;
    }
    if(it==(str.end()-1))
    {
    cout<<xiaohua<<":"<<enemy<<endl;
    }
    }
    return 0;
    }
    这道题并没有给出数据范围,用string可以不用考虑数组开多大。emmmmm,尤其要注意特殊情况,嗯嗯,就是0:0的问题。我的特殊情况处理可能有点差劲,去看看其他人的代码

  • 0
    @ 2017-11-25 01:12:34
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main()
    {
        char a[80000]={'0'};
        char tmp;
        int count=0;
        cin >> tmp;
        while(!(tmp=='E'))
            if (!(tmp=='\n') && !(tmp=='\0')) { a[count]=tmp; count++; cin >> tmp; }
    
        int ptr, cw, cl, k, t=0;
    
        k=11;
    LABEL:
        ptr=0;
        cw=0;
        cl=0;
        while (ptr!=count+1)
        {
            if (a[ptr]=='W') cw++; else if (a[ptr]=='L') cl++;
            ptr++;
            if ((cw>=k || cl>=k) && abs(cw-cl)>=2) 
                { cout << cw << ':' << cl << endl; cw=0; cl=0; }
        }
        cout << cw << ':' << cl << endl << endl;
        
        t++;
        k=21;
        if(t==1) goto LABEL;
    
        return 0;
    }
    
  • 0
    @ 2017-11-20 19:36:23

    1、数组空间尽量大
    2、比赛正好结束,要开始下一场比赛。

    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    void getScore(char *beg,int totle){
        int red = 0,
            blue = 0;
        while(*beg!=69){
            if(red>=totle||blue>=totle){
                if(abs(red-blue)>=2){
                    printf("%d:%d\n",red,blue);
                    red=0,blue=0;
                }
            }
            if(*beg==87)
                red++;
            else if(*beg==76)
                blue++;
            beg++;
        }
        printf("%d:%d\n",red,blue);
        if((red>=totle||blue>=totle)&&abs(red-blue)>=2)
            printf("0:0\n");
    }
    
    int main()
    {
        char *letBeg;
        char *letAry = malloc(10000);    //开辟大的空间正确,否则存在错误
        scanf("%c",letAry);
        letBeg = letAry;
        while(*letAry!=69){
            if(*letAry==87||*letAry==76){
                letAry++;
            }
            scanf("%c",letAry);
        }
        getScore(letBeg,11);
        printf("\n");
        getScore(letBeg,21);
        return 0;
    }
    
    
  • 0
    @ 2017-11-20 19:34:30

    1、数组空间尽量的大,100000
    2、注意开始直接输入E的情况
    3、最后一个报错,是因为没有考虑正好结束,要开始下一场比赛。

    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    void getScore(char *beg,int totle){
        int red = 0,
            blue = 0;
        while(*beg!=69){
            if(red>=totle||blue>=totle){
                if(abs(red-blue)>=2){
                    printf("%d:%d\n",red,blue);
                    red=0,blue=0;
                }
            }
            if(*beg==87)
                red++;
            else if(*beg==76)
                blue++;
            beg++;
        }
        printf("%d:%d\n",red,blue);
        if((red>=totle||blue>=totle)&&abs(red-blue)>=2)
            printf("0:0\n");
    }
    
    int main()
    {
        char *letBeg;
        char *letAry = malloc(10000);    //开辟大的空间正确,否则存在错误
        scanf("%c",letAry);
        letBeg = letAry;
        while(*letAry!=69){
            if(*letAry==87||*letAry==76){
                letAry++;
            }
            scanf("%c",letAry);
        }
        getScore(letBeg,11);
        printf("\n");
        getScore(letBeg,21);
        return 0;
    }
    
    
  • 0
    @ 2017-11-07 22:50:03

    非递归的写法,刚开始res数组500不能AC,改成了10000才行

    思路是设置两个数组res11,res22分别储存比分,
    两个指针 p11 , p22代表当前场次编号
    在读到'E'之前,每次循环读入一个字符,并进行判断,若比赛结束指针+1

    //
    // Created by eh5 on 17-11-7.
    //
    
    #include <stdio.h>
    #include <stdlib.h>
    
    struct sc {
        int w;
        int l;
    };
    int state(int a,int b,int sc){
        if(a<sc && b<sc) return 0;
        else if(abs(a-b) >1) return 1;
        return 0;
    }
    
    int main(){
        int C;
        struct sc res11[10000],res21[10000];
        int p11=0,p21=0;
        while((C=getchar())!='E'){
            if((C != 'W') && (C != 'L')) continue;
    
    
            if(C == 'W'){
                res11[p11].w += 1;
                res21[p21].w += 1;
            } else  {
                res11[p11].l += 1;
                res21[p21].l += 1;
            }
            if(state(res11[p11].w ,res11[p11].l,11)){
                p11++;
            }
            if(state(res21[p21].w ,res21[p21].l,21)){
                p21++;
            }
        }
        for(int i=0;i<=p11;i++){
            printf("%d:%d\n",res11[i].w,res11[i].l);
        }
        printf("\n");
        for(int i=0;i<=p21;i++){
            printf("%d:%d\n",res21[i].w,res21[i].l);
        }
    
    }
    
  • 0
    @ 2017-11-07 18:54:36

    小学数学题
    没什么可说的
    代码:
    dalao不喜勿喷

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    int L_11[20001],W_11[20001],L_21[20001],W_21[20001],len_11=1,len_21=1;
    int main(){
        char ch;
        ch=getchar();
        while(ch!='E')
        {
            if(ch=='W')
                W_11[len_11]++;
            else if(ch=='L')
                L_11[len_11]++;
                if((W_11[len_11]>=11 && W_11[len_11]-L_11[len_11]>=2) || (L_11[len_11]>=11 && L_11[len_11]-W_11[len_11]>=2))
                    len_11++;
                if(ch=='W')
                    W_21[len_21]++;
                else if(ch=='L')
                    L_21[len_21]++;
                if((W_21[len_21]>=21 && W_21[len_21]-L_21[len_21]>=2) || (L_21[len_21]>=21 && L_21[len_21]-W_21[len_21]>=2))
                len_21++;
                ch=getchar();
        }
        for(int i=1;i<=len_11;i++)
            printf("%d:%d\n",W_11[i],L_11[i]);
        printf("\n");
        for(int i=1;i<=len_21;i++)
            printf("%d:%d\n",W_21[i],L_21[i]);
        return 0;
    }
    
  • 0
    @ 2017-11-05 21:00:37

    难点。。。一在规则,二在读入
    给新手的建议:
    1.能用cin别用其他的,除非数据特别大,你永远不知道getchar之类的会造成什么后果(洛谷是卡getchar的,亲测)
    2.大部分在线OJ,对于有多个输出的题目,可以即时输出,但是为了保险,一般存储完最后输出(一些交互式题目或云端评测除外)
    3.好好读题,信竞从来就不是纯理科。。。到后来就会体会到读不懂题的恐惧
    贴两组代码,一组是刚入坑的代码,一组是最近写的,没想到思路居然还惊人相似呢。。。
    NOIP备战最后几天,考完之后不知道还会不会学,看将来吧。。。
    刚入坑时代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int l[2][10000];int m[2][100000];
    int main()
    {
        char a='c';
        int x=0,y=0,u=0,v=0,i=0,k=0;
        for(;a!='E';)
        {
            a=getchar();
            if(a=='W')
            {
            x++;u++;
            }
            if(a=='L')
            {
            y++;v++;
            } 
            if((x>=11&&x-y>=2)||(y>=11&&y-x>=2))
            {
                m[0][k]=x;m[1][k]=y;k++;x=0;y=0;
            }
            if((u>=21&&u-v>=2)||(v>=21&&v-u>=2))
            {
                l[0][i]=u;l[1][i]=v;i++;u=0;v=0;
            }
        }
    
        for(int p=0;p<k;p++)
        cout<<m[0][p]<<":"<<m[1][p]<<endl;
        cout<<x<<":"<<y<<endl;
        cout<<endl; 
        for(int h=0;h<i;h++)
        cout<<l[0][h]<<":"<<l[1][h]<<endl;  
        cout<<u<<":"<<v;
        return 0;
        
    } 
    

    现在代码

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int ans[300][2],ans2[300][2];
    int main()
    {
        char c;
        int sum1=0,sum2=0,sum3=0,sum4=0,zong=0,gong1=0,gong2=0,i;
        while(cin>>c)
        {
            if(c=='E')
             {
                gong1++;gong2++;
                ans[gong1][0]=sum1;
                ans[gong1][1]=sum2;
                ans2[gong2][0]=sum3;
                ans2[gong2][1]=sum4;
                break;
             }
             if(c=='W')
             {
              sum1++;
              sum3++;
             }
            if(c=='L')
             {
              sum2++;
              sum4++;
             }
            if((sum1>=11||sum2>=11)&&abs(sum1-sum2)>=2)
              {
                gong1++;
                ans[gong1][0]=sum1;
                ans[gong1][1]=sum2;
                sum1=0;
                sum2=0;
              }
            if((sum3>=21||sum4>=21)&&abs(sum3-sum4)>=2)
              {
                gong2++;
                ans2[gong2][0]=sum3;
                ans2[gong2][1]=sum4;
                sum3=0;
                sum4=0;
              }
        } 
        for(i=1;i<=gong1;i++)
         cout<<ans[i][0]<<":"<<ans[i][1]<<endl;
        cout<<endl;
        for(i=1;i<=gong2;i++)
         cout<<ans2[i][0]<<":"<<ans2[i][1]<<endl;
        return 0;
    }
    
  • 0
    @ 2017-11-02 11:49:56

    我这个是用java写的,看了一下别的题解都没有java的 所以我来上传一下。用String和StringBuilder都可以,字符串简单点。代码如下:

    import java.util.Scanner;

    public class Main {
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    StringBuilder s=new StringBuilder();
    // String s =new String();
    int x=0; //第一次出现E的位置
    while(true)//while(s.charAt(x)!='E')
    {
    s.append(sc.nextLine());
    // s+=sc.nextLine();
    x=s.indexOf("E");
    if(x!=-1)break;
    }
    int hua=0;
    int huad=0;
    int hua2=0;
    int huad2=0;

    for (int i = 0; i<x; i++) {
    if(s.charAt(i)=='W')
    hua++;
    if(s.charAt(i)=='L')
    huad++;
    if((hua==11&&huad==0)||(hua==0&&huad==11)||(hua>=11&&(hua-huad)>=2)
    || (huad>=11&&(huad-hua)>=2))
    {
    System.out.println(hua+":"+huad);
    hua=0;
    huad=0;
    }

    }
    System.out.println(hua+":"+huad);
    System.out.println();

    for (int i = 0; i < x; i++) {
    if(s.charAt(i)=='W')
    hua2++;
    if(s.charAt(i)=='L')
    huad2++;
    if((hua2==21&&huad2==0)||(hua2==0&&huad2==21)||(hua2>=21&&(hua2-huad2)>=2)
    || (huad2>=21&&(huad2-hua2)>=2))
    {
    System.out.println(hua2+":"+huad2);
    hua2=0;
    huad2=0;
    }

    }
    System.out.println(hua2+":"+huad2);
    }
    }

  • 0
    @ 2017-10-24 06:34:09

    来个不用字符串的

    #include<bits/stdc++.h>
    using namespace std;
    int aa[10001],bb[10001];
    int main()
    {
        char a;
        int l=0,r=0,ll=0,rr=0,s=1;
        while(1)
        {
            scanf("%c",&a);
            if(a=='E')
            {
                printf("%d:%d\n",l,r);
                aa[s]=ll;
                bb[s]=rr;
                printf("\n");
                for(int i=1;i<=s;i++)
                {
                    printf("%d:%d\n",aa[i],bb[i]);
                }
                return 0;
            }
            if(a=='W')
            {
                l++;
                ll++;
            }
            if(a=='L')
            {
                r++;
                rr++;
            }
            if((l>=11||r>=11)&&(l-r>=2||r-l>=2))
            {
                printf("%d:%d\n",l,r);
                l=0;
                r=0;
            }
            if((ll>=21||rr>=21)&&(ll-rr>=2||rr-ll>=2))
            {
                aa[s]=ll;
                bb[s]=rr;
                s++;
                ll=0;
                rr=0;
            }
        }
    }
    
  • 0
    @ 2017-10-24 00:14:01

    新手python,没动脑子。
    sba=0
    sbb=0
    nba=0
    nbb=0
    shuju=[]
    ansa=[]
    ansb=[]
    while True :
    s=raw_input()
    if "E" not in s:
    shuju.append(s)
    else:
    shuju.append(s[:s.find("E")])
    break
    for a in shuju:
    for i in range(len(a)):
    if a[i]=="W":
    sba+=1
    nba+=1
    elif a[i]=="L":
    sbb+=1
    nbb+=1
    if (sba>=11 or sbb>=11) and abs(sba-sbb)>=2:
    ansa.append(str(sba)+":"+str(sbb))
    sba=0
    sbb=0
    if (nba>=21 or nbb>=21) and abs(nba-nbb)>=2:
    ansb.append(str(nba)+":"+str(nbb))
    nba=0
    nbb=0

    ansa.append(str(sba)+":"+str(sbb))
    ansb.append(str(nba)+":"+str(nbb))
    for i in ansa:
    print i
    print ""
    for i in ansb:
    print i

信息

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