蓝桥练习第一天 2023/10/17

#单词分析:

我的:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
  char vocabulary[1000];
  int shell[1000]={0};
  scanf("%s", vocabulary);
  int i = 0;
  int len = strlen(vocabulary);
  for (i = 0; i < len; i++)
  {
    int d = vocabulary[i]; //对照ascal码值 ; 
    if (d < 97)
    {
      d = d + 32;   //如果检测到大写字母则将数值加32转化为小写字母; 
    }
    shell[d]++;
  }
  int count; 
  int max = shell[97];
  int maxnumber = 97;
  for (count=98;count<= 122;count++)
  {
    if (shell[count] > max)
    {
      max = shell[count];
      maxnumber = count;
    }
    else{
    	continue;
	}
  }
  printf("%c\n", maxnumber);
  printf("%d", max);
  return 0;
}

 

 别人的:

#include<stdio.h>
int main()
{
    char ch;
    int count[26]={0},max=0,i;
    while((ch=getchar())!=EOF)
    {
        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;
}

       值得学习的地方:

1.数组必须初始化,初始化方式如图所示;字符串数组可以不初始化如若初始化可char ch[number]={'\0'};

2.对一段字符串进行处理可以不用创建字符串数组,可以利用用户输入存在缓冲区,而getchar从缓冲区中只读一个字符来挨个处理字符;

3.代码简化:

将printf("%c\n".....);

printf("%d"....);并行为一行;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值