Translate Your Own Language

Thursday, July 18, 2019

A2 online judge 193. Omar Loves Candies, Again Solution

A2 online judge 193. Omar Loves Candies, Again Solution

A2 online judge 193. Omar Loves Candies, Again Solution 

Problem Link: https://a2oj.com/p?ID=193

Solution:


 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
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int i, j, c=0, maxc=0;
        string s;
        char ch;
        cin>>s;
        for(i=0; i<(int)s.size(); i++)
        {
            c=0;
            for(j=0; j<(int)s.size(); j++)
            {
                if(s[i]==s[j])
                    c++;
            }
            if(maxc < c)
            {
                maxc = c;
                ch = s[i];
            }
            if(maxc == c)
            {
                if(ch > s[i])
                    ch = s[i];
            }
        }

        cout<<maxc<<" "<<ch<<endl;
    }
}



8 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete