2 条题解

  • 0
    @ 2022-7-17 10:17:59

    C :

    #include <stdio.h>
    #include <stdlib.h>
    #define MAXN 1000000
    
    int main(void)
    {
    	char ch;
    	int i, w, l;
    	char score[MAXN];
    	i = 0;
    	while ((ch = getchar()) != EOF) {
    		if (ch >= 'A' && ch <= 'Z')
    			score[i++] = ch;
    	}
    	score[i] = '\0';
    	l = w = 0;
    	for (i = 0; score[i] != '\0'; ++i) {
    		if (score[i] == 'W')
    			w++;
    		else if (score[i] == 'L')
    			l++;
    		else if (score[i] == 'E') {
    			printf("%d:%d\n", w, l);
    		}
    		if ((l >= 11 && abs(l-w) > 1) || 
    				(w >= 11 && abs(l-w) >1)) {
    			printf("%d:%d\n", w, l);
    			l = w = 0;
    		}
    	}
    	putchar('\n');
    
    	w = l = 0;
    	for (i = 0; score[i] != '\0'; ++i) {
    		if (score[i] == 'W')
    			w++;
    		else if (score[i] == 'L')
    			l++;
    		else if (score[i] == 'E') {
    			printf("%d:%d\n", w, l);
    		}
    		if ((l >= 21 && abs(l-w) > 1) || 
    				(w >= 21 && abs(l-w) >1)) {
    			printf("%d:%d\n", w, l);
    			l = w = 0;
    		}
    	}
    	return 0;
    }
    

    C++ :

    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
      char ch[100000];
      int i=0,p=0,q=0,j;
    
      while(ch[i]!='E'){
    	i++;  
    	cin>>ch[i];  
      }
      for(j=1;j<=i;j++){
    	if(ch[j]=='W')
    	  p++;
        else if(ch[j]=='L')
    	  q++;
        if(((p>10||q>10)&&abs(p-q)>=2)){
          cout<<p<<':'<<q<<endl;
    	  p=q=0;
    	}
        if(ch[j]=='E'){
          cout<<p<<':'<<q<<endl;
    	  p=q=0;
    	}	
      }
      cout<<endl;
      for(j=1;j<=i;j++){
    	if(ch[j]=='W')
    	  p++;
        else if(ch[j]=='L')
    	  q++;
        if(((p>20||q>20)&&abs(p-q)>=2)){
          cout<<p<<':'<<q<<endl;
    	  p=q=0;
    	}	
        if(ch[j]=='E'){
          cout<<p<<':'<<q<<endl;
    	  p=q=0;
    	}		
      }
      return 0;
    }
    

    Python :

    # coding=utf-8
    import sys
    
    score = []
    me = 0
    me2 = 0
    other = 0
    other2 = 0
    real_score = []
    real_score2 = []
    flag = True
    
    for line in sys.stdin.readlines():
        score.append(line)
    for i in score:
        if flag is False:
            break
        for j in i:
            if j == 'W':
                me += 1
                me2 += 1
            elif j == 'L':
                other += 1
                other2 += 1
            elif j == 'E':
                real_score.append('%d:%d' % (me, other))
                real_score2.append('%d:%d' % (me2, other2))
                flag = False
                break
            if (me == 11 and (me - other) >= 2) or ((other - me) >= 2 and other == 11):
                real_score.append('%d:%d' % (me, other))
                me = 0
                other = 0
            elif (me > 11 or other > 11) and abs(me - other) >= 2:
                real_score.append('%d:%d' % (me, other))
                me = 0
                other = 0
            if (me2 == 21 and (me2 - other2) >= 2) or ((other2 - me2) >= 2 and other2 == 21):
                real_score2.append('%d:%d' % (me2, other2))
                me2 = 0
                other2 = 0
            elif (me2 > 21 or other2 > 21) and abs(me2 - other2) >= 2:
                real_score2.append('%d:%d' % (me2, other2))
                me2 = 0
                other2 = 0
    if flag:
        real_score.append('%d:%d' % (me, other))
        real_score2.append('%d:%d' % (me2, other2))
    
    
    for i in real_score:
        print(i)
    print()
    for j in real_score2:
        print(j)
    

    信息

    ID
    761
    时间
    3000ms
    内存
    64MiB
    难度
    9
    标签
    递交数
    314
    已通过
    35
    上传者