Skip to content

Commit 758c652

Browse files
committed
added omar loves candies from a2oj
1 parent c540474 commit 758c652

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Omar can get as many candies as he wants but all of them must be of the same type. Find the candy having the biggest quantity in the store so that Omar can have maximum number of candies.
2+
3+
4+
Input Format:
5+
6+
The first line of the input will be a single integer T, the number of test cases (1 <= T <= 100). Followed by the test cases, each test case is described in one line which contains a non-empty string which consists of up to 100 letters, each letter is a lower case English letter (from 'a' to 'z'). This string represents all candies in the store, each candy is described using 1 character, so if the string is "abac" this means the store contains 2 candies of type 'a', 1 candy of type 'b' and 1 candy of type 'c'.
7+
8+
9+
Output Format:
10+
11+
For each test case, print a single line which contains a single integer representing the maximum number of candies that Omar can get followed by a space then a letter which represents the kind of that candy. If there are multiple candies with the same number, print the one which occurs relatively first in the English alphabet.
12+
13+
14+
Sample Input:
15+
3
16+
abac
17+
abc
18+
zzz
19+
20+
21+
Sample Output:
22+
2 a
23+
1 a
24+
3 z

Omar and Candies/Solution.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
#include<stdlib.h>
4+
5+
int main()
6+
{
7+
int t;
8+
scanf("%d",&t);
9+
while(t--){
10+
char str[100];
11+
scanf("%s",str);
12+
int i;
13+
int *arr = (int*)calloc(26,sizeof(int));
14+
for(i=0;i<strlen(str);i++){
15+
arr[str[i]-97]++;
16+
}
17+
int max=arr[0],c=0;
18+
for(i=1;i<26;i++)
19+
{
20+
if(arr[i]>max){
21+
max = arr[i];
22+
c=i;
23+
}
24+
}
25+
printf("%d %c\n",max,c+97);
26+
}
27+
return 0;
28+
}

0 commit comments

Comments
 (0)