Problem A. Scoring Board

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
-

题目的大概意思是

在程序设计比赛中,计分板以一种特殊的规则记录选手的提交情况

  1. 没有提交,则展示出“-”
  2. 提交结果为AC之前没有提交结果为WA的展示出“+”
  3. 提交了k次后还是WA,没有出现AC的,则展示出“-k”
  4. 经过了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();//随手好习惯
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值