2 条题解
-
1
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)
-
0
作为一道入门题,本题是一道考验思维的很好的题目
#include <bits/stdc++.h> using namespace std; void eleven(string a) { int l=0,r=0; for(int i=0;i<a.size();i++) { if(a[i] == 'W') l++; else if(a[i] == 'L') r++; if((l>=11 || r>=11) && abs(l-r)>1) { cout << l << ":" << r << endl; l = r = 0; } } cout << l << ":" << r << endl; } void twelve(string a) { int l=0,r=0; for(int i=0;i<a.size();i++) { if(a[i] == 'W') l++; else if(a[i] == 'L') r++; if((l>=21 || r>=21) && abs(l-r)>1) { cout << l << ":" << r << endl; l = r = 0; } } cout << l << ":" << r << endl;; } int main() { string a = ""; char ch = ' '; while(ch!='E') { if(ch == 'W' || ch == 'L') a+=ch; ch = getchar(); } eleven(a); cout << endl; twelve(a); return 0; }
- 1
信息
- ID
- 761
- 时间
- 3000ms
- 内存
- 64MiB
- 难度
- 8
- 标签
- 递交数
- 320
- 已通过
- 39
- 上传者