THE BEAUTY AND THE GEEKS– EDITORIAL
Author: bigo_admin
Tester and Editorialist: subhasis10
Problem Links:- Contest
and Practice
DIFFICULTY: EASY
PREREQUISITES: Strings, Conversion of character to integer
PROBLEM:
Given a string of which each character represents a number. Print the maximum occurring number
and if there are more than one then print “DRAW”.
EXPLANATION:
We need to take input of IDs in the form of a string. Each character in the string represents an integer ID. So first we need to convert the character into an integer. We then make an integer array a[10] of counters for each ID from 0 to 9 since IDs are all of single integers. Now we traverse through the string. For every value in the string, we increment the counter corresponding to that ID. The maximum value of that array (a[]) represents the maximum occurring ID.
CODE:
#include #include #include int main() { int t; scanf("%d",&t); while(t-- ) { char ch[10000]; scanf("%s",ch); int len = strlen(ch); int a[10] = {0}; for(int i=0;imx) mx = a[i],draw = false,idx = i; else if(a[i]==mx) draw = true; } if(draw) printf("DRAW"); else printf("%d",idx); printf("\n"); } return 0; }