Problem Description
Problem Analysis
Just count how many times each letter appears and compute the answer.
One slightly tricky part is that the two gs at the start and end are allowed to overlap,
so that case needs to be handled separately.
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
| #include<stdio.h>
#include<string.h>
char s[100200];
int main() {
while(scanf("%s",s)!=EOF) {
int l=strlen(s);
int a[7]= {0,0,0,0,0,0,0};
for(int j=0; j<l; j++) {
if(s[j]=='g')
a[0]++;
else if(s[j]=='o')
a[1]++;
else if(s[j]=='d')
a[2]++;
else if(s[j]=='m')
a[3]++;
else if(s[j]=='r')
a[4]++;
else if(s[j]=='n')
a[5]++;
else if(s[j]=='i')
a[6]++;
}
a[0]=a[0]-1;
a[1]=a[1]/3;
a[5]=a[5]/2;
int min=999999;
for(int j=0; j<7; j++)
if(min>a[j])
min=a[j];
printf("%d\n",min);
}
return 0;
}
|
Problem link: 【DidaOJ】[1143]String)