[SWEA] 7792 반장 선출

Time Lapse :21min 2sec

7792.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
using namespace std;

int main(int argc, char** argv){
int test_case;
int T, N, cnt;
bool alphas[26];
string str;
char c;
scanf("%d",&T);
for(test_case = 1; test_case <= T; ++test_case){
scanf("%d",&N);
vector<vector<string>> students(21,vector<string>());
getchar();
for(int i = 0; i<N; i++){
str.clear();
while(1){
c=getchar();
if(c==' '||('A'<=c&&c<='Z'))
str += c;
else
break;
}
cnt = 0;
memset(alphas,false,sizeof(alphas));
for(int j=0;j<str.length();j++){
if('A'<=str[j]&&str[j]<='Z'&&!alphas[str[j]-'A']){
alphas[str[j]-'A'] = true; ++cnt;
}
}
students[cnt].push_back(str);
}
for(int i=20; i>=0; i--){
if(students[i].size()!=0){
sort(students[i].begin(),students[i].end());
printf("#%d %s\n",test_case,students[i][0].c_str());
break;
}
}
}
return 0;//정상종료시 반드시 0을 리턴해야합니다.
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/7792/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.