题解

355 条题解

  • 25
    @ 2017-04-15 15:21:58
    #include<iostream>
    #include<cmath>
    using namespace std;
    
    char letter[100000];
    void Output(int cap,int type) {
        int w = 0, l = 0;
        for (int i = 0; i < cap; i++) {
            if (letter[i] == 'W')
                w++;
            if (letter[i] == 'L')
                l++;
            if (((w == type||l==type)&&(abs(l-w)>=2))||((w>type||l>type)&&(abs(l-w)==2)) ){
                cout << w << ':' << l;
                w = 0, l = 0;
                cout << endl;
            }
        }
        cout << w << ':' << l;
    }
    int main() {
        int i = 0;
        while ((letter[i] = getchar()) != EOF) {
            if (letter[i] == 'E')
                break;
            i++;
        }
        Output(i, 11);
        cout << endl<<endl;
        Output(i, 21);
    
        return 0;
    }
    
  • 17
    @ 2017-03-01 16:39:38

    题目很简单,细节要考虑周到:
    1.第一个点直接读入了一个‘E’;
    2.最后一个点是在一次完整的计分并输出后————即此时比分为0:0,那么就要输出‘0:0’(题目中有提示;
    3.刚刚上面有个括号补全;
    4.为什么我按一下enter它自动给我加了一个‘4.’;
    5.这个网站好强啊!
    6.代码反正也没人读就不贴了!

    • @ 2017-05-18 10:39:51

      代码有人看啊,像我一样的新手不懂了就一个一个看过来的……

    • @ 2018-04-30 11:15:47

      @子化: 有人看啊,菜鸟在看,希望注释详细点

  • 6
    @ 2018-02-09 21:15:42

    看了好久都没java的,来一波java版本的,要注意是若干行!

    import java.util.Scanner;
    //交叉模拟  把比赛的情况模拟出来 
    public class Main {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            StringBuilder sb = new StringBuilder();
            String res, string;
            while(true) {
                string = in.nextLine();
                if (string.contains("E")) {
                    sb.append(string);
                    break;
                }
                sb.append(string);
            }
            res = sb.toString();
            in.close();
            char[] ch = new char[res.length()];
            ch = res.toCharArray();
            getPoints(ch, 11);
            System.out.println();
            getPoints(ch, 21);
        }
        private static void getPoints(char[] record, int point) {
            int me = 0;
            int you = 0;
            for (int i = 0; i < record.length; i ++) {
                if (record[i] == 'E') {
                    System.out.println(me + ":" + you);
                    break;
                }
                if (record[i] == 'W') {
                    me ++;
                }
                if (record[i] == 'L') {
                    you ++;
                }
                if (me >= point || you >= point) {
                    if (Math.abs(me - you) >= 2) {
                        System.out.println(me + ":" + you);
                        me = 0;
                        you = 0;
                    }
                }
            }
        }
    }
    
  • 4
    @ 2017-02-26 21:34:32

    #include <stdio.h>
    #include <math.h>
    char s[100000];
    int main()
    {
    int i = 0,j,a=0,b=0;

    do{
    scanf("%c",&s[i]);
    }while(s[i++]!='E');

    for(j=0;j<i-1;j++)
    {
    if(s[j]=='W')
    a++;
    if(s[j]=='L')
    b++;
    if(s[j]=='\n')
    continue;
    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;
    }
    }
    }
    printf("%d:%d\n",a,b);
    a=0;
    b=0;

    printf("\n");

    for(j=0;j<i-1;j++)
    {
    if(s[j]=='W')
    a++;
    if(s[j]=='L')
    b++;
    if(s[j]=='\n')
    continue;
    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;
    }
    }
    }
    printf("%d:%d",a,b);
    return 0;
    }

    • @ 2017-02-26 21:35:45

      为什么这里数组要设置成100000才能通过测评

      我一开始100就不行

    • @ 2018-02-15 17:04:47

      @miaojie4321: 数组空间太少 容易出错

  • 3
    @ 2017-10-08 10:26:56

    这一题真强,题目不难,坑点太多。
    下面给一个代码,缩进我是调好的,如果错了就不要怪我

    #include <cstdio>
    char a[1000005];
    int main(){
        char c;
        c=getchar();
        int len=0;
        while(c!='E'&&c!=EOF){
            if(c=='W'||c=='L'){
                a[++len]=c;
            }
            c=getchar();
        }
        int awin=0,bwin=0;
        for(int i=1;i<=len;i++){
            if(a[i]=='W'){
                awin++;
                if(awin>=11&&awin-bwin>=2){
                    printf("%d:%d\n",awin,bwin);
                    awin=0,bwin=0;
                }
            }
            if(a[i]=='L'){
                bwin++;
                if(bwin>=11&&bwin-awin>=2){
                    printf("%d:%d\n",awin,bwin);
                    awin=0,bwin=0;
                }
            }
        }
        printf("%d:%d\n",awin,bwin);
        awin=bwin=0;
        puts("");
        for(int i=1;i<=len;i++){
            if(a[i]=='W'){
                awin++;
                if(awin>=21&&awin-bwin>=2){
                    printf("%d:%d\n",awin,bwin);
                    awin=0,bwin=0;
                }
            }
            if(a[i]=='L'){
                bwin++;
                if(bwin>=21&&bwin-awin>=2){
                    printf("%d:%d\n",awin,bwin);
                    awin=0,bwin=0;
                }
            }
        }
        printf("%d:%d\n",awin,bwin);
        awin=bwin=0;
        return 0;
    }
    
    
  • 2
    @ 2019-05-26 17:41:15
    #include<iostream>
    #include<cstdlib>
    #include<string>
    using namespace std;
    int main()
    {
        string s1,s2;//方便输入
        while(getline(cin,s2))s1+=s2;//输入字符串
        int i=0,a=0,b=0;//i是指针,a统计了赢的次数,b是输的次数
        while(s1[i]!='E')//只要不是结束符,现在是判断11分制
        {
            switch(s1[i])//switch判断s1[i]
            {
                case 'W':a++;break;//如果s1[i]是‘W’,累计到a里
                case 'L':b++;break;//如果s1[i]是‘E’,累计到b里
            }
            if((a>=11||b>=11)&&(abs(a-b)>=2))//是否到达条件,一盘有没有结束
            {
                cout<<a<<":"<<b<<endl;//输出
                a=0;b=0;//清零,下一盘
            }
            i++;//下一个字符
        }
        cout<<a<<":"<<b<<endl;//剩下的也要输完
        cout<<endl;//换行隔开
        a=b=0;i=0;//清零,换了一个分制
        while(s1[i]!='E')//同理
        {
            switch(s1[i])
            {
                case 'W':a++;break;
                case 'L':b++;break;
            }
            if((a>=21||b>=21)&&(abs(a-b)>=2))
            {
                cout<<a<<":"<<b<<endl;
                a=0;b=0;
            }
            i++;
        }
        cout<<a<<":"<<b<<endl;
        return 0;
    }
    
  • 2
    @ 2017-03-22 21:38:28

    *var
    a:array[0..100000] of char;
    ch:char;
    t,i,x,y:longint;
    begin
    t:=0;
    repeat
    read(ch);
    if (ch='W') or (ch='L') then
    begin
    inc(t);
    a[t]:=ch;
    end;
    until ch='E';//读入:注意数据中有换行
    x:=0;y:=0;
    for i:=1 to t do
    begin
    if a[i]='W' then inc(x);
    if a[i]='L' then inc(y);
    if abs(x-y)>=2 then//分差大于等于2
    if (x>=11) or (y>=11) then
    begin
    writeln(x,':',y);
    x:=0;y:=0;
    end;
    end;
    writeln(x,':',y);//0:0也要输出
    writeln;//11分制
    x:=0;y:=0;
    for i:=1 to t do
    begin
    if a[i]='W' then inc(x);
    if a[i]='L' then inc(y);
    if abs(x-y)>=2 then
    if (x>=21) or (y>=21) then
    begin
    writeln(x,':',y);
    x:=0;y:=0;
    end;
    end;
    writeln(x,':',y);//21分制
    end.

  • 2
    @ 2016-05-18 20:36:02

    小田君又来发题解了~~~
    模拟题,秒过。附代码:
    #include <stdio.h>

    int main(){
    // freopen("Table.in","r",stdin);
    // freopen("Table.out","w",stdout);
    int i = 0,c = 0,d = 0,x = 0,y = 0,cnt;
    char F[100001],a;
    scanf("%c",&a);
    while(a != 'E'){
    F[i] = a;
    if(a == 'W') c++;
    else if(a == 'L') d++;
    if((c >= 11&&c-d >= 2)||(d >= 11&&d-c >= 2)){
    printf("%d:%d\n",c,d);
    c = 0,d = 0;
    }
    i++;
    scanf("%c",&a);
    }
    printf("%d:%d\n\n",c,d);
    for(cnt = 0; cnt < i; cnt++){
    if(F[cnt] == 'W') x++;
    else if(F[cnt] == 'L') y++;
    if((x >= 21&&x-y >= 2)||(y >= 21&&y-x >= 2)){
    printf("%d:%d\n",x,y);
    x = 0,y = 0;
    }
    }
    printf("%d:%d\n\n",x,y);

    return 0;
    }

  • 1
    @ 2019-07-29 18:58:57

    #include<iostream>
    #include<math.h>
    using namespace std;

    char s[1024*1024];

    void result(int length,int full){
    int W=0,L=0;
    for(int i=0;i<length;i++){
    if(s[i]=='W')
    W++;
    else if(s[i]=='L')
    L++;
    if(max(W,L)>=full && abs(W-L)>=2){
    cout<<W<<':'<<L<<endl;
    W=L=0;
    }
    }
    cout<<W<<':'<<L<<endl;
    }

    int main(){
    int i=0;
    while((s[i] = getchar()) != EOF){
    if(s[i]=='E')
    break;
    i++;
    }
    result(i,11);
    cout<<endl;
    result(i,21);
    return 0;
    }

    用上max()和abs()函数,会比较简洁

  • 1
    @ 2019-06-07 13:45:50
    #include <iostream>
    #define f(x) ((x) < 0 ? (-(x)) : (x))
    using namespace std;
    void match(string &s, int limit){
        int k = 0, w = 0, l = 0;
        while(k < s.length()){
            if(s[k] == ' '){
                k++;
                continue;
            }
            if(s[k] == 'W') w++;
            if(s[k] == 'L') l++;
            k++;
            if((w >= limit || l >= limit) && f(w - l) > 1){
                cout << w << ':' << l << endl;
                w = l = 0;
            }
        }
        cout << w << ':' << l << endl;
        putchar('\n');
        return ;
    }
    int main(){
        string s;
        string ans;
        while(getline(cin, s)){
            if(s.find('E') == string::npos)
                ans.append(s);
            else{
                ans.append(s.substr(0, s.find('E')));
                break;
            }
        }
        match(ans, 11);
        match(ans, 21);
        return 0;
    }
    
    
  • 1
    @ 2019-01-21 22:34:40

    被坑了两次😂😂😂第一次没看清输出,第二次数组太小😂😂😂
    菜了菜了,还是来水一下题解吧

    #include <cstdio>
    #include <cstring>
    char s[100000];

    int abs(int a,int b)
    {
    int c;
    if (a>b)
    {
    c=a-b;
    }
    if (b>a)
    {
    c=b-a;
    }
    return c;
    }

    void output(int total,int type)
    {
    int w=0,l=0;
    for (int i=0;i<=total;i++)
    {

    if (s[i]=='W')
    {
    w++;
    }
    if (s[i]=='L')
    {
    l++;
    }
    if (s[i]=='E')
    {
    printf("%d:%d\n",w,l);
    }
    if ((w>=type||l>=type)&&(abs(w,l)>1))
    {
    printf("%d:%d\n",w,l);
    w=0;l=0;
    }
    }
    }

    int main()
    {
    int i=0;
    while (scanf("%c",&s[i])!=EOF)
    {
    if (s[i]=='E') break;
    i++;
    }
    output(i,11);
    printf("\n");
    output(i,21);
    return 0;
    }

  • 1
    @ 2018-10-24 11:52:40

    这是我能想到的最简单的代码了,MAX=2000的时候有一个RE所以设置到了4000。

    #include <iostream>
    using namespace std;

    const int MAX=4000;
    int a[MAX*2], b[MAX*2], c[MAX], d[MAX];

    int main(){
    char ch;
    int m=0, n=0;
    while (cin>>ch && ch!='E'){
    if (ch=='W'){
    a[m]++;
    c[n]++;
    if (a[m]>=11 && a[m]-b[m]>1) m++;
    if (c[n]>=21 && c[n]-d[n]>1) n++;
    }
    else{
    b[m]++;
    d[n]++;
    if (b[m]>=11 && b[m]-a[m]>1) m++;
    if (d[n]>=21 && d[n]-c[n]>1) n++;
    }
    }

    for (int i=0; i<=m; i++)
    cout<<a[i]<<":"<<b[i]<<endl;
    cout<<endl;
    for (int i=0; i<=n; i++)
    cout<<c[i]<<":"<<d[i]<<endl;

    return 0;
    }

  • 1
    @ 2018-08-25 21:29:15
    string=''
    def do_work(src):
        w = l = 0
        for ch in string:
            if ch == 'E':
                print("{}:{}".format(w,l))
                return
            elif ch == 'W':
                w += 1
            elif ch == 'L':
                l += 1
            if abs(w-l)>1 and (w>=src or l>=src):
                #print(w,':',l)
                print("{}:{}".format(w,l))
                w = l = 0
    
    
    while 1:
        s = input()
        string += s
        if s.find('E') != -1:
            break
    
    do_work(11)
    print()
    do_work(21)
    

    这才叫简洁 kakaka

  • 1
    @ 2018-08-05 22:05:50
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int i = 0,game1 = 0,game2 = 0,flag = 0;
        int score1[10000][2],score2[10000][2];
        char a[100000];
        while((a[i] = getchar()) != 'E')
        {
            i++;
        }
        i = 0;
        do
        {
            score1[game1][0] = 0;
            score1[game1][1] = 0;
            while((score1[game1][0] < 11 && score1[game1][1] < 11)||abs(score1[game1][0] - score1[game1][1]) <= 1)
            {
                if(a[i] == 'W')
                {
                    score1[game1][0]++;
                    i++;
                }
                else if(a[i] == 'L')
                {
                    score1[game1][1]++;
                    i++;
                }
                else if(a[i] == 'E')
                {
                    flag = 1;
                    break;
                }
                else
                {
                    i++;
                    continue;
                }
            }
            game1++;
            if(!flag && a[i] == 'E')
            {
                game1++;
                score1[game1][0] = 0;
                score1[game1][1] = 0;
            }
        }while(a[i] != 'E');
    
        i = 0;
        do
        {
            score2[game2][0] = 0;
            score2[game2][1] = 0;
            while((score2[game2][0] < 21 && score2[game2][1] < 21)||abs(score2[game2][0] - score2[game2][1]) <= 1)
            {
                if(a[i] == 'W')
                {
                    score2[game2][0]++;
                    i++;
                }
                else if(a[i] == 'L')
                {
                    score2[game2][1]++;
                    i++;
                }
                else if(a[i] == 'E')
                {
                    flag = 1;
                    break;
                }
                else
                {
                    i++;
                    continue;
                }
            }
                game2++;
            if(!flag && a[i] == 'E')
            {
                game2++;
                score2[game2][0] = 0;
                score2[game2][1] = 0;
            }
        }while(a[i] != 'E');
        for(i = 0; i < game1; i++)
            printf("%d:%d\n",score1[i][0],score1[i][1]);
        printf("\n");
        for(i = 0; i < game2; i++)
            printf("%d:%d\n",score2[i][0],score2[i][1]);
        return 0;
    }
    
    
  • 1
    @ 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) ;
    }
    
  • 1
    @ 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);
        }
    
    }
    
  • 1
    @ 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;
            }
        }
    }
    
  • 1
    @ 2017-02-20 16:30:55

    一开始开了一个10000的数组结果炸RE了,晕死

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    char b[100000]={0};
    int main(void)
    {
        int count1=0,count2=0,now=0;
        char a;
        while((a=getchar())!='E')
        {
            if(a=='L'||a=='W')
                b[now++]=a;     
        }
        for(int i=0;i<now;i++)
        {
            if(b[i]=='W')
                count1++;
            else count2++;
            if((count1==11&&count2<=9)||(count2==11&&count1<=9))
            {
                cout<<count1<<':'<<count2<<'\n';
                count1=0;
                count2=0;
                continue;
            }
            else if((count1>=11&&count2>=10)||(count2>=11&&count1>=10))
            {
                if(count1-count2>=2||count1-count2<=-2)
                {
                    cout<<count1<<':'<<count2<<'\n';
                    count1=0;
                    count2=0;
                    continue;
                }
            }
        }
        cout<<count1<<':'<<count2<<'\n'<<'\n';
        count1=0;count2=0;
        for(int i=0;i<now;i++)
        {
            if(b[i]=='W')
                count1++;
            else count2++;
            if((count1==21&&count2<=19)||(count2==21&&count1<=19))
            {
                cout<<count1<<':'<<count2<<'\n';
                count1=0;
                count2=0;
                continue;
            }
            else if((count1>=21&&count2>=20)||(count2>=21&&count1>=20))
            {
                if(count1-count2>=2||count1-count2<=-2)
                {
                    cout<<count1<<':'<<count2<<'\n';
                    count1=0;
                    count2=0;
                    continue;
                }
            }
        }
        cout<<count1<<':'<<count2<<endl;
    }
    
  • 0
    @ 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;
    }

  • 0
    @ 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;
    }

信息

ID
1217
难度
7
分类
字符串 点击显示
标签
递交数
16276
已通过
3691
通过率
23%
上传者