max char in array

 // Online C++ compiler to run C++ program online

#include <iostream>

#include<string>

#include<algorithm>

using namespace std;

int main() {

    // Write C++ code here

   string s="aabbbccccaaddbaaa";

   char check[50];

   for(int i=0;i<26;i++){

       check[i]=0;

   }

   for(int i=0;i<26;i++){

       cout<<check[i];

   }

   

   for(int i=0;i<s.size();i++){

       check[s[i]-'a']++;

   }

   int max=0;

   int maxind;

   for(int i=0;i<26;i++){

       if(check[i]>max){

           max=check[i];

           maxind=i;

       }

   }

   cout<<max<<endl;

   char ch=char(maxind+'a');

   cout<<maxind+'a'<<endl;

   cout<<ch<<endl;


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings