Problem A. Scoring Board
广西2019年程序设计大赛第一题
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 512 megabytes
In programming contests, the scoring board shows each team’s judge results. Assume there is only one
problem in the contest, the scoring board will show according to the rules below:
• When there is no submissions, the scoring board will show “-”.
• When there is no “WA” before “AC”, the scoring board will show “+”.
• When the team failed to solve the problem, the scoring board will show “-k”, where k is the number
of “WA”.
• When the team passed the problem with several tries, the scoring board will show “+k”, where k is
the number of “WA” before “AC”.
Please write a program to show the scoring board.
Input
The first line of the input contains an integer T(1 ≤ T ≤ 50), denoting the number of test cases.
In each test case, there is one integer n(0 ≤ n ≤ 50) in the first line, denoting the number of submissions.
In the second line, there are n strings s1, s2, . . . , sn(si ∈ {“AC”, “WA”}), denoting the judge results of each
submission. The submissions have already been sorted by time.
Output
For each test case, print a single line, denoting what the scoring board shows.
Example
standard input
5
4
WA WA WA AC
5
WA WA WA AC WA
1
AC
2
WA WA
0
standard output
+3
+3
+
-2
-
题目的大概意思是
在程序设计比赛中,计分板以一种特殊的规则记录选手的提交情况
- 没有提交,则展示出“-”
- 提交结果为AC之前没有提交结果为WA的展示出“+”
- 提交了k次后还是WA,没有出现AC的,则展示出“-k”
- 经过了k次WA的提交,最终出现AC的,则展示出“+k”
解题
就是一个简单输入输出的题目,根据题目要求判断输入的是AC还是WA,然后记录WA的次数就可以了
Java参考代码如下:
import java.util.Scanner;
public class A_ScoringBoard {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
int n,sum = 0;
String []str;
while(t-- > 0) {
n = in.nextInt();
if(n == 0) { //没有提交 直接输出 -
System.out.println("-");
continue;
}
str = new String[n];
for(int i = 0; i < n; i++) {
str[i] = in.next();
if(str[i].equals("WA")) {//判断是AC还是WA
sum++;
if(sum == n) {//试了n次,都WA
System.out.println("-"+sum);
}
}else if(str[i].equals("AC")) {
if(sum == 0) {//前面没有AC
System.out.println("+");
}else if(sum < n) {//出现sum次WA后得到AC
System.out.println("+" + sum);
}
continue;
}
}
sum=0;//记录已经出现的错误次数
}
in.close();//随手好习惯
}
}