HzuMRL


私信TA

用户名:1710819057

访问量:11450

签 名:

算法菜鸡萌新

等  级
排  名 442
经  验 4701
参赛次数 7
文章发表 27
年  龄 0
在职情况 学生
学  校 贺州学院
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
 char zimu[26];
 int shu[26];
};
int main()
{
    int temp,tm,num,qm=1,sp,sm,max,min;
    char x_p[1000];
    cin>>num;
    getchar();
    struct node std[num];
 for(sp=0;sp<num;sp++)
 {
  gets(x_p);
  tm=0;
  temp=strlen(x_p);
  std[sp].zimu[tm]=x_p[0];
  std[sp].shu[tm]=1;
  for(int im=1;im<temp;im++)
  {
  
      for(int jm=0;jm<=tm;jm++)
      {
        if(x_p[im]==std[sp].zimu[jm])
         {
          std[sp].shu[jm]+=1;
          break;
          }
         else if(jm==tm)
          {
            tm++;
            std[sp].zimu[tm]=x_p[im];
            std[sp].shu[tm]=0;
         }
    
       }    
  }
  max=1;
  for(sm=0;sm<=tm;sm++)  
  {
       if(std[sp].shu[sm]>max)
       {
            max=std[sp].shu[sm];
            min=sm;
        }
       else if(std[sp].shu[sm]==max)
           {
            if(std[sp].zimu[sm]<std[sp].zimu[min])
                     min=sm;
                 else
                  continue;
               }
  }
  printf("%c %d\n",std[sp].zimu[min],std[sp].shu[min]);
 }
    return 0;
}

 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区