当前位置:网站首页>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;
}边栏推荐
- 长投学堂帮忙开证券账户是安全靠谱的吗?个人如何开
- Steady! How thousands of micro services can quickly access Zadig (helm chart)
- 国盛证券开户是真的安全可靠吗
- Simple understanding of counting and sorting
- [kotlin] beautiful pop-up box, custom pop-up box (dialog box), extension function, chrysanthemum waiting bar, message prompt box
- Is it safe and reliable to open a securities account in changtou school?
- Business atlas in super factory
- 题解 洛谷P1762 偶数/6.21校内考试T2
- Mono 的执行流程
- 【网关开发】ngx嵌套lua时处理CIDR表示的IP地址段
猜你喜欢

Multiomics single cell data integration and regulatory reasoning based on graph linked embedding

Wechat red envelope cover making tutorial and use guide with link jump

如何结合均线分析伦敦金行情走势线图

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

Pytorch builds transformer to realize multivariable and multi step time series forecasting (load forecasting)

邂逅阿维塔 11:强产品力下久违的新鲜感

CS5463代码模块解析(包含下载链接)
Sample code of using redis to realize the like function

keil工程,程序写多后,RTT不能打印

【Word 教程系列第 1 篇】如何去除 Word 表格中的箭头
随机推荐
在长投学堂开通证券账户是安全可靠的吗?
老家出资,俞敏洪设立两支基金
国盛证券开户是真的安全可靠吗
How to analyze the trend chart of London gold market with the moving average
SqlServer复习
After crossing, she said that the multiverse really exists
两栏布局左边图片显示部分由右边内容高度决定
Panxiaoming, senior vice president of IC nansha|amd and President of Greater China: process, architecture and platform optimization break through the computing boundary
Multiomics single cell data integration and regulatory reasoning based on graph linked embedding
Interpretation of papers (DCN) towards k-means-friendly spaces: simultaneous deep learning and clustering
00 后云原生工程师:用 Zadig 为思创科技(广州公交)研发开源节流
How to solve the problem of desktop without sound
Simple understanding of counting and sorting
QtCreator5.15.0源码编译全过程记录
【网关开发】ngx嵌套lua时处理CIDR表示的IP地址段
网上办理股票开户安全性高吗?
【HackTheBox】 meow
一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂
torch. nn. Transformer import failed
Explanation: Luogu p1762 even number /6.21 internal examination T2