题目描述
乒乓球是谁先打满11或21分,且至少领先对手两分就算胜利
java 代码
import java.io.*;
import java.util.*;
public class Main{
static Scanner in = new Scanner(System.in);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void work(char[] s, int n){
int W = 0, L = 0;
for(int i=0; i<s.length && s[i]!='E'; i++){
if(s[i]=='W') W++;
else L++;
if(W>=n || L>=n){
if(Math.abs(W-L)>=2){
out.println(W+":"+L);
W = 0; // 清零
L = 0;
}
}
}
out.println(W+":"+L);
}
public static void main(String[] args)throws IOException{
StringBuilder sb = new StringBuilder();
while(in.hasNext()) sb.append(in.nextLine());
char[] s = sb.toString().toCharArray();
work(s, 11);
out.println();
work(s, 21);
out.flush();
out.close();
}
}