当前位置:网站首页>C語言-單詞分析解析
C語言-單詞分析解析
2022-06-28 23:03:00 【王陳鋒】
題目描述
小藍正在學習一門神奇的語言,這門語言中的單詞都是由小寫英文字母組 成,有些單詞很長,遠遠超過正常英文單詞的長度。小藍學了很長時間也記不住一些單詞,他准備不再完全記憶這些單詞,而是根據單詞中哪個字母出現得最多來分辨單詞。
現在,請你幫助小藍,給了一個單詞後,幫助他找到出現最多的字母和這 個字母出現的次數。
輸入描述
輸入一行包含一個單詞,單詞只由小寫英文字母組成。
對於所有的評測用例,輸入的單詞長度不超過 1000。
輸出描述
輸出兩行,第一行包含一個英文字母,錶示單詞中出現得最多的字母是哪 個。如果有多個字母出現的次數相等,輸出字典序最小的那個。
第二行包含一個整數,錶示出現得最多的那個字母在單詞中出現的次數。
輸入輸出樣例
示例 1
輸入
lanqiao
輸出
a
2
示例 2
輸入
longlonglongistoolong
輸出
o
6
#include <stdio.h>
#include <stdlib.h>
int read(char *str);
int main(int argc, char *argv[])
{
// 請在此輸入您的代碼
char str[1000];
scanf("%s",str);
read(str);
return 0;
}
int read(char *str)
{
int i=0,j=0,max=0,max1=0;
char zimu[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int count[26]={0};
for(i=0;i<26;i++){
for(j=0;str[j]!='\0';j++){
if(zimu[i]==str[j])
count[i]++;
}
}
for(i=0;i<26;i++)
{
if(count[i]>max)
{
max=count[i];
max1=i;
}
}
printf("%c\n",zimu[max1]);
printf("%d",max);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
// 請在此輸入您的代碼
int count[26]={0},max=0,i;
char ch;
while((ch=getchar())!='\n')
count[ch-'a']++;
for(i=1;i<26;i++)
if(count[i]>count[max])
max=i;
printf("%c\n%d",max+'a',count[max]);
return 0;
}边栏推荐
猜你喜欢

Basic knowledge diagram of K-line Diagram -- meaning of single K-line

Interpretation of papers (DCN) towards k-means-friendly spaces: simultaneous deep learning and clustering

【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码

Online text filter less than specified length tool

在线SQL转HTMLTable工具
oracle设置密码复杂度及设置超时退出的功能

After crossing, she said that the multiverse really exists

Linux Installation mysql5.7 (centos7.6) tutorial

直击产业落地 | 飞桨重磅推出业界首个模型选型工具

CS5463代码模块解析(包含下载链接)
随机推荐
Leetcode 324 Swing sort II [tri double pointeur] le chemin du leetcode pour l'héroding
Wave picking of WMS warehouse management system module
Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
CS5463代码模块解析(包含下载链接)
go语言插件平台的实现思路
【Try to Hack】nmap
Embedded dynamic Arabic string conversion LCD display string [thanks for Jianguo ambition]
CPU、GPU、TPU、NPU区别
【Word 教程系列第 2 篇】Word 中如何设置每页的表格都有表头
复杂嵌套的对象池(4)——管理多类实例和多阶段实例的对象池
手机办理股票开户安全性高吗?
两栏布局左边图片显示部分由右边内容高度决定
Web API learning notes 1
With the development of industrial Internet as the starting point, the industry can enter a new stage of development
Huawei cloud gaussdb (for redis) unveiling issue 19: inventory of six second level capabilities
k线图基础知识图解——单根K线的含义
生产环境sonarqube安装
Complex nested object pool (4) -- manage the object pool of multi class instances and multi-stage instances
【深度学习】(2) Transformer 网络解析,代码复现,附Pytorch完整代码
[sword finger offer] 50 First character that appears only once