AtCoder Beginner Contest 173 B Problem "Judge Status Summary" Explanation (Python3, C ++, Java)

AtCoder Beginner Contest 173 B Problem I will explain the "Judge Status Summary".

Problem URL: https://atcoder.jp/contests/abc173/tasks/abc173_b

Problem summary

$ N $ of string $ S_i $ representing the test case judge result is given. Find the number of judges whose results were'AC',' WA',' TLE', and'RE', respectively.

Constraint

・ $ 1 \ leq N \ leq 10 ^ 5 $ ・ $ S_i $ is one of'AC','WA','TLE','RE'

Commentary

You can implement it according to the problem statement. For example ・ The number of'AC'is $ C_0 $, ・ The number of'WA'is $ C_1 $, ・ The number of'TLE'is $ C_2 $, ・ The number of'RE'is $ C_3 $, Create four variables called Initialize each with 0, Conditional branching is performed for $ N $ $ S_i $ to manage variables. After that, if you output as shown in the output example, you can AC.

Below are examples of solutions in Python3, C ++, and Java.

Example of answer for each language

Example solution in 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)
Example solution in 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 answer example

{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 ("character string A") can be used to determine whether S is equal to character string A.

Recommended Posts

AtCoder Beginner Contest 173 B Problem "Judge Status Summary" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 174 B Problem "Distance" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 177 B Problem "Substring" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 169 B Problem "Multiplication 2" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 175 B Problem "Making Triangle" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 176 B Problem "Multiple of 9" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 176 C Problem "Step" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 170 B Problem "Crane and Turtle" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 167 B Problem "Easy Linear Programming" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 166 A Explanation of Problem "A? C" (Python3, C ++, Java)
AtCoder Beginner Contest 167 A Problem "Registration" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 170 A Problem "Five Variables" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 169 A Explanation of Problem "Multiplication 1" (Python3, C ++, Java)
AtCoder Beginner Contest 176 A Explanation of problem "Takoyaki" (Python3, C ++, Java)
AtCoder Beginner Contest 175 A Problem "Rainy Season" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 174 A Problem "Air Conditioner" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 177 A Problem "Don't be late" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 177 C Problem "Sum of product of pairs" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 174 C Problem (Python)
AtCoder Beginner Contest 165 A Problem "We Love Golf" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest # 002 C Problem
Atcoder Beginner Contest A, B Input summary Python that tends to be a problem
AtCoder Regular Contest # 002 C Problem
Atcoder Beginner Contest 152 Kiroku (python)
[AtCoder explanation] Control ABC180 A, B, C problems with Python!
[AtCoder explanation] Control ABC188 A, B, C problems with Python!
[AtCoder explanation] Control ABC158 A, B, C problems with Python!
[AtCoder explanation] Control ABC164 A, B, C problems with Python!
[AtCoder explanation] Control ABC168 A, B, C problems with Python!
ABC127 A, B, C Explanation (python)
ABC126 A, B, C Explanation (python)
[Python] [Explanation] AtCoder Typical DP Contest: A Contest
Python beginner Atcoder memo @ KEYENCE 2020, ABC problem
AtCoder Beginner Contest: D Question Answers Python
[AtCoder explanation] Control the A, B, C problems of ABC182 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC185 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
AtCoder Beginner Contest 177
AtCoder Beginner Contest 179
[AtCoder explanation] Control the A, B, (C), D problems of ABC165 with Python!
[AtCoder explanation] Control the A, B, C, D problems of ABC183 with Python!
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder Beginner Contest 173
Atcoder Beginner Contest 153
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
[AtCoder explanation] Control the A, B, C, D problems of ABC181 with Python!
Solving with Ruby, Perl, Java and Python AtCoder diverta 2019 Programming Contest C String Manipulation
AtCoder Beginner Contest 177 Problem C I tried to find out why it was wrong
Solve Atcoder ABC176 (A, B, C, E) in Python
AtCoder Beginner Contest 152 Review
AtCoder Beginner Contest 181 Note
AtCoder Beginner Contest 187 Note
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 166 Review
AtCoder Beginner Contest 167 Review
AtCoder Beginner Contest 182 Note