当前位置:网站首页>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;
}边栏推荐
- 如何使用伦敦金画出支撑阻力线
- Is it safe and reliable for changtou school to help open a securities account? How to drive
- 一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂
- 微搭低代码中实现二维码生成
- Websocket for im instant messaging development: concept, principle and common sense of mistakes
- 论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》
- 非科班!自学之路!
- The Best of Many Worlds_ Dual Mirror Descent for Online Allocation Problems
- Zadig + cave Iast: let safety dissolve in continuous delivery
- Master the usage of const
猜你喜欢

00 後雲原生工程師:用 Zadig 為思創科技(廣州公交)研發開源節流

Flowable boundary timer

Business atlas in super factory

Wave picking of WMS warehouse management system module

Zadig + cave Iast: let safety dissolve in continuous delivery

00 后云原生工程师:用 Zadig 为思创科技(广州公交)研发开源节流

如何使用伦敦金画出支撑阻力线

Hit the industry directly | the flying propeller launched the industry's first model selection tool
利用Redis实现点赞功能的示例代码

Wechat red envelope cover making tutorial and use guide with link jump
随机推荐
How to solve the problem of desktop without sound
[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word
leetCode-栈类型详解
00 後雲原生工程師:用 Zadig 為思創科技(廣州公交)研發開源節流
【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码
LeCun预言AGI:大模型和强化学习都是斜道!我的世界模型才是新路
国盛证券开户是真的安全可靠吗
【kotlin】好看的弹出框、自定义弹出框(对话框)、扩展函数、菊花等待条、消息提示框
How to use London gold to draw support resistance line
Prometeus 2.36.0 新特性
两栏布局左边图片显示部分由右边内容高度决定
强大的开源API接口可视化管理平台-YApi
Qt5.15中qsrand,srand随机数生成函数已弃用问题
CS5463代码模块解析(包含下载链接)
Explanation: Luogu p1762 even number /6.21 internal examination T2
Is it safe to open a stock account by mobile phone?
在线文本过滤小于指定长度工具
Steady! How thousands of micro services can quickly access Zadig (helm chart)
Realization of 2D code generation in micro build low code
Online linear programming: Dual convergence, new algorithms, and regret bounds