字符串中包含最多的字符

Posted cgy1012

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串中包含最多的字符相关的知识,希望对你有一定的参考价值。


#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;

 

我:

 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;

 

以上是关于字符串中包含最多的字符的主要内容,如果未能解决你的问题,请参考以下文章