ZeroJudge b309 - 聖杯戰爭

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

題目網址
A ~ J 對應其代表的英靈,接下來的字母也比照辦理。

Solution

注意英靈順序即可。

Code

ZJ b309ZJ b309
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
#include<cstdio>
#include<cstring>
#include<cctype>
#define N 10000001
char str[N];
int main()
{
char *name[7] = { "Saber", "Lancer", "Archer", "Rider", "Caster", "Assassin", "Berserker" };
int n[7] = {}, i;
while (fgets(str, N, stdin))
{
int len = strlen(str);
for (i = 0; i < len; i++)
{
if (isalpha(str[i]))
n[(tolower(str[i]) - 'a') % 7]++;
}
}

int max = 0;
for (i = 0; i < 7; i++)
if (max < n[i])
max = n[i];

for (i = 7; i >= 0; i--)
if (n[i] == max)
{
puts(name[i]);
break;
}

return 0;
}