String contains the most characters


#include<string>
#include<iostream>
#include<sstream>
using namespace std;

int main()
{
 string in;
 cin >> in;
 int len = in.length();
 int temp[26] = { 0 };
 for (int i = 0; i < len; i++)
 {
  int t = in[i] - 'a';
  temp[t]++;
 }
 int res = 0;
 for (int i = 0; i < 26; i++)
 {
  if (temp[i] > res)
   res = temp[i];
 }
 cout << res;

}

 

I:

 string str;
//cout<<"输入:";
 cin>>str;

int length=str.length();
map<char,int> mp;

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

 mp[str[i]]++;

}

int size=mp.size();
int temp=0;
int j;
for( j=0;j<size;j++)
{
if(mp[str[j]]>temp)
{
 temp= mp[str[j]];
}
}

cout<<temp;

 

Guess you like

Origin www.cnblogs.com/cgy1012/p/11441060.html