AtCoder Beginner Contest 173
Time Limit: 2 sec / Memory Limit: 1024 MB
Score :200200points
Problem Statement
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.
The problem hasNNtest cases.
For each test caseii(1≤i≤N1≤i≤N), you are given a stringAC
,WA
,TLE
, andRE
, respectively.
See the Output section for the output format.
Constraints
- 1≤N≤1051≤N≤105
- SiSiis
AC
,WA
,TLE
, orRE
.
Input
Input is given from Standard Input in the following format:
NN S1S1 ⋮⋮ SNSN
Output
LetC0,C1,C2C2, andC3be the numbers of test cases for which the verdict isAC
,WA
,TLE
, andRE
, respectively. Print the following:
AC x C0 WA x C1 TLE x C2 RE x C3
Sample Input 1Copy
Copy6 AC TLE AC AC WA TLE
Sample Output 1Copy
CopyAC x 3 WA x 1 TLE x 2 RE x 0
We have33AC
,WA
,TLE
, andRE
, respectively.
解題思路:小學計數問題,不過多解釋,看題目就能懂
解法1,利用字串模擬:
#include<cstdio> #include<cstring> using namespace std; int main(void) { int n; int a[4]; char ch[10]; char str[4][10]={{"AC"},{"WA"},{"TLE"},{"RE"}}; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); getchar(); for(int i=0;i<n;++i) { scanf("%s",ch); for(int j=0;j<4;++j) { if(strcmp(ch,str[j])==0) a[j]++; } } for(int i=0;i<4;++i) printf("%s x %d\n",str[i],a[i]); } return 0; }
解法2,利用STL的map:
#include<iostream> #include<cstdio> #include<map> using namespace std; int main(void) { ios::sync_with_stdio(false); map<string,int> mp; int n; char ch[10]; while(cin>>n) { for(int i=0;i<n;++i) cin>>ch,mp[ch]++; printf("AC x %d\n",mp["AC"]); printf("WA x %d\n",mp["WA"]); printf("TLE x %d\n",mp["TLE"]); printf("RE x %d\n",mp["RE"]); } return 0; }