0
0

More than 3 years have passed since last update.

AtCoder Beginner Contest 173 B問題「Judge Status Summary」解説(Python3,C++,Java)

Last updated at Posted at 2020-08-11

AtCoder Beginner Contest 173 B問題「Judge Status Summary」の解説を行います。

問題URL : https://atcoder.jp/contests/abc173/tasks/abc173_b

問題概要

テストケースのジャッジ結果を表す文字列$S_i$が$N$個与えられる。
ジャッジ結果が'AC','WA','TLE','RE'であったものの個数をそれぞれ求めよ。

制約

・$1 \leq N \leq 10^5$
・$S_i$は'AC','WA','TLE','RE'のいずれか

解説

問題文の通りに実装を行えばよいです。
例えば、
・'AC'である個数を$C_0$,
・'WA'である個数を$C_1$,
・'TLE'である個数を$C_2$,
・'RE'である個数を$C_3$,
という4つの変数を作成し、
それぞれを0で初期化し、
$N$個の$S_i$について条件分岐を行って変数を管理します。
その後、出力例のように出力すればACすることが出来ます。

以下、Python3,C++,Javaでの解答例を示します。

各言語解答例

Python3での解答例
B.py
N = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for i in range(N):
  S = input()
  if S == "AC":
    c0 += 1
  elif S == "WA":
    c1 += 1
  elif S == "TLE":
    c2 += 1
  elif S == "RE":
    c3 += 1
print("AC", "x",c0)
print("WA", "x",c1)
print("TLE", "x",c2)
print("RE", "x",x3)

C++での解答例
B.cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int c0 = 0;
  int c1 = 0;  
  int c2 = 0;
  int c3 = 0;
  for (int i = 0; i < n; i++){
    string S;
    cin >> S;
    if (S == "AC"){
      c0 += 1;
    }else if (S == "WA"){
      c1 += 1;
    }else if (S == "TLE"){
      c2 += 1;
    }else if (S == "RE"){
      c3 += 1;
    }
  }
  cout << "AC" << " " << "x" << " " << c0 << endl;
  cout << "WA" << " " << "x" << " " << c1 << endl;
  cout << "TLE" << " " << "x" << " " << c2 << endl;
  cout << "RE" << " " << "x" << " " << c3 << endl;
}

Javaでの解答例
B.java
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int c0 = 0;
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    for (int i = 0; i < n; i++){
      String S = scan.next();
      if (S.equals("AC")){
        c0 += 1;
      }else if (S.equals("WA")){
        c1 += 1;
      }else if (S.equals("TLE")){
        c2 += 1;
      }else if (S.equals("RE")){
        c3 += 1;
      }
    }
    System.out.println("AC"+" "+"x"+" "+c0);
    System.out.println("WA"+" "+"x"+" "+c1);
    System.out.println("TLE"+" "+"x"+" "+c2);
    System.out.println("RE"+" "+"x"+" "+c3);
  }
}

※S.equals("文字列A")でSが文字列Aと等しいかを判定することが出来ます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0