1 条题解

  • 0
    @ 2021-6-14 23:29:29

    C :

    #include <stdio.h>  
    #include <stdlib.h>  
    #include <string.h>  
    int main()  
    {  
        char a[100000];  
        char c;  
        int win=0,lost=0;  
        int totle;  
        int i=0;  
        scanf("%c",&c);  
        while(c != EOF && c!='E')  
        {  
            //if(c!='\n')  
                a[i++]=c;  
            scanf(" %c",&c);    
        }  
          
        totle=i;  
            for(i=0;i<totle;i++)  
        {  
            if(a[i]=='W') win++;else lost++;  
            if((win>=11|| lost>=11) && abs(win-lost)>=2)  
            {  
                printf("%d:%d\n",win,lost);  
                win=0;  
                lost=0;  
            }   
              
        }  
        printf("%d:%d\n",win,lost);  
        printf("\n");  
        win=0;  
        lost=0;  
         
        for(i=0;i<totle;i++)  
        {  
            if(a[i]=='W') win++;else lost++;  
            if((win>=21|| lost>=21) && abs(win-lost)>=2)  
            {  
                printf("%d:%d\n",win,lost);  
                win=0;  
                lost=0;  
            }   
              
        }  
        printf("%d:%d\n",win,lost);  
        return 0;  
    }
    
    

    C++ :

    #include<stdio.h> 
    #include<string.h> 
    char c[100000]; 
    int main() 
    { 
        char a[30]; 
        int m=0,p=0,w=0,l=0,sum=0,i; 
        while(~scanf("%s",a)) 
        { 
            w=0,l=0,sum=0; 
            for(i=0;i<strlen(a);i++) 
            { 
                if(a[i]!='E'&&p==0) 
                { 
                    c[m]=a[i]; 
                    m++; 
                } 
                if(a[i]=='E') 
                { 
                    p=1; 
                    break; 
                } 
            } 
            if(p==1) 
                break; 
        } 
        for(i=0;i<m;i++) 
        { 
            if(c[i]=='W') 
                w++; 
            else
                l++; 
            if(w>=11&&w-l>=2||l>=11&&l-w>=2) 
            { 
                printf("%d:%d\n",w,l); 
                sum=sum+w+l; 
                w=0,l=0; 
            } 
        } 
        if(sum==m) 
            printf("0:0\n"); 
        else
            printf("%d:%d\n",w,l); 
        puts(""); 
        w=0,l=0,sum=0; 
        for(i=0;i<m;i++) 
        { 
            if(c[i]=='W') 
                w++; 
            else
                l++; 
            if(w>=21&&w-l>=2||l>=21&&l-w>=2) 
            { 
                printf("%d:%d\n",w,l); 
                sum=sum+w+l; 
                w=0,l=0; 
            } 
        } 
        if(sum==m) 
            printf("0:0\n"); 
        else
            printf("%d:%d\n",w,l); 
        return 0; 
    }
    

    Pascal :

    var ch:char;i,win,lose:longint;s:ansistring;
    begin
      read(ch);
      while ch<>'E' do
        begin
          if ord(ch)<>0 then s:=s+ch;
          read(ch);
        end;
      for i:=1 to length(s) do
        begin
          if s[i]='W' then inc(win);
          if s[i]='L' then inc(lose);
          if (win>=11)or(lose>=11) then
            if abs(win-lose)>=2 then
              begin
                writeln(win,':',lose);
                win:=0;lose:=0;
              end;
        end;
      writeln(win,':',lose);
      writeln;
      win:=0;lose:=0;
      for i:=1 to length(s) do
        begin
          if s[i]='W' then inc(win);
          if s[i]='L' then inc(lose);
          if (win>=21)or(lose>=21) then
            if abs(win-lose)>=2 then
              begin
                writeln(win,':',lose);
                win:=0;lose:=0;
              end;
        end;
      writeln(win,':',lose);
    end.
    

    Java :

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    public class Main {
    	public static void main(String args[]) throws Exception {
    
    		// 输入单次结果
    		Scanner scanner = new Scanner(System.in);
    		List<String> resultList = new ArrayList<String>();
    		boolean enough = false;
    		while (scanner.hasNextLine()) {
    			String input = scanner.nextLine();
    			for (int i = 0; i < input.length(); i++) {
    				String result = input.substring(i, i + 1);
    				if ("E".equals(result)) {
    					enough = true;
    					break;
    				} else {
    					resultList.add(result);
    				}
    
    			}
    			if (enough) {
    				break;
    			}
    		}
    
    		// 输出比赛结果(21分制)
    		fun(resultList, 11);
    		System.out.println();
    		fun(resultList, 21);
    	}
    
    	public static void fun(List<String> resultList, int spot) {
    		if (resultList.size() == 0) {
    			System.out.println("0:0");
    			return;
    		}
    		int win = 0;
    		int lose = 0;
    		for (String result : resultList) {
    			if (result.equals("W")) {
    				win++;
    			}
    			if (result.equals("L")) {
    				lose++;
    			}
    			if ((win >= spot && (win - lose) >= 2)
    					|| (lose >= spot && (lose - win) >= 2)) {
    				System.out.println(win + ":" + lose);
    				win = 0;
    				lose = 0;
    			}
    		}
    
    		System.out.println(win + ":" + lose);
    
    	}
    
    }
    
    
    • 1