当前位置: 首页 > news >正文

广西住房和建设厅网站长沙自动seo

广西住房和建设厅网站,长沙自动seo,怎么做视频解析网站吗,天津代理记账本专栏为c语言练习专栏,适合刚刚学完c语言的初学者。本专栏每天会不定时更新,通过每天练习,进一步对c语言的重难点知识进行更深入的学习。 今日练习题关键字:字符个数统计 多数元素 投票法 💓博主csdn个人主页&#xf…

本专栏为c语言练习专栏,适合刚刚学完c语言的初学者。本专栏每天会不定时更新,通过每天练习,进一步对c语言的重难点知识进行更深入的学习。

今日练习题关键字:字符个数统计 多数元素 投票法

在这里插入图片描述

💓博主csdn个人主页:小小unicorn
⏩专栏分类:C语言天天练
🚚代码仓库:小小unicorn的代码仓库🚚
🌹🌹🌹关注我带你学习编程知识

Day1

  • 题目一:
    • 题目描述:
    • 解题思路:
    • 代码实现:
    • 结果情况:
  • 题目二:
    • 题目描述:
    • 解题思路:
    • 代码实现:
    • 结果情况:
  • 总结:

题目一:

题目描述:

题目来源:字符个数统计
编写一个函数,计算字符串中含有的不同字符的个数。字符在 ASCII 码范围内( 0~127 ,包括 0 和 127 ),换行表示结束符,不算在字符里。不在范围内的不作统计。多个相同的字符只计算一次
例如,对于字符串 abaca 而言,有 a、b、c 三种不同的字符,因此输出 3 。
数据范围: 1≤n≤500

在这里插入图片描述

解题思路:

运用的是HASH表的思想,因为只有最多只有128种数据,所以只需维护一个大小为128的字符数组,让输入的字符作为数组下标,取出这个下标数组中的字符直接与输入的字符比较(不用for循环从头再查),如果相同则跳过,不同则赋值,让结果++,最后遇到’\n’结束循环,返回结果即可。

代码实现:

#include<stdio.h>int main() 
{int hash[128] = {0};char B;int count = 0;while (scanf("%1c", &B) != EOF) {int asc = (int)B;if (hash[asc] != 1) {count++;hash[asc] = 1;}}printf("%d", count - 1); //需要去掉最后的回车键
}

结果情况:

在这里插入图片描述
符合题目要求,问题得到解决。

题目二:

题目描述:

题目来源:多数元素
给定一个大小为 n 的数组 nums ,返回其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。
你可以假设数组是非空的,并且给定的数组总是存在多数元素。

在这里插入图片描述

解题思路:

投票法

因为多数元素在数组里出现的次数绝对大于n/2,所以用不同元素消去相同元素,剩下的必然是相同元素

代码实现:

int majorityElement(int* nums, int numsSize)
{int candidate=nums[0];//投票对象int count=1;//票数for(int i=1;i<numsSize;i++)//遍历投票对象{if(nums[i]==candidate)//投票对象相同,票数+1{count++;}else//投票对象不同,票数-1{count--;if(count<0)//该元素不是多数元素,更新投票对象candidate并把票数置1{candidate=nums[i];count=1;}}}return candidate;
}

结果情况:

在这里插入图片描述
符合题目要求,问题得到解决。

总结:

文章到这里就要告一段落了,有更好的想法或问题,欢迎评论区留言。
希望今天的练习能对您有所收获,咱们下期见!


文章转载自:
http://raker.fcxt.cn
http://imputrescibility.fcxt.cn
http://timbrel.fcxt.cn
http://homostyly.fcxt.cn
http://rampage.fcxt.cn
http://natatory.fcxt.cn
http://golgotha.fcxt.cn
http://miniskirt.fcxt.cn
http://adjoint.fcxt.cn
http://carshalton.fcxt.cn
http://biocybernetics.fcxt.cn
http://repudiate.fcxt.cn
http://himation.fcxt.cn
http://intragalactic.fcxt.cn
http://mussuck.fcxt.cn
http://rabbitry.fcxt.cn
http://manyat.fcxt.cn
http://generotype.fcxt.cn
http://vacuole.fcxt.cn
http://secrete.fcxt.cn
http://breconshire.fcxt.cn
http://defiantly.fcxt.cn
http://clianthus.fcxt.cn
http://dibromide.fcxt.cn
http://extraordinary.fcxt.cn
http://unpresented.fcxt.cn
http://lampwick.fcxt.cn
http://nullarbor.fcxt.cn
http://tantalization.fcxt.cn
http://galenist.fcxt.cn
http://weeds.fcxt.cn
http://strikeover.fcxt.cn
http://epicentrum.fcxt.cn
http://kaleidoscopic.fcxt.cn
http://cyme.fcxt.cn
http://reppo.fcxt.cn
http://sandy.fcxt.cn
http://animatingly.fcxt.cn
http://morbific.fcxt.cn
http://otp.fcxt.cn
http://cherenkov.fcxt.cn
http://return.fcxt.cn
http://histoplasmosis.fcxt.cn
http://serotherapy.fcxt.cn
http://telelens.fcxt.cn
http://redbone.fcxt.cn
http://lyssa.fcxt.cn
http://seccotine.fcxt.cn
http://clumsily.fcxt.cn
http://libeccio.fcxt.cn
http://kirschsteinite.fcxt.cn
http://synclastic.fcxt.cn
http://panelling.fcxt.cn
http://alod.fcxt.cn
http://preponderance.fcxt.cn
http://gager.fcxt.cn
http://akureyri.fcxt.cn
http://furunculosis.fcxt.cn
http://nonhygroscopic.fcxt.cn
http://virgate.fcxt.cn
http://lampedusa.fcxt.cn
http://accoucheuse.fcxt.cn
http://dawk.fcxt.cn
http://nonoxidizable.fcxt.cn
http://narcodiagnosis.fcxt.cn
http://triggerfish.fcxt.cn
http://iea.fcxt.cn
http://vahah.fcxt.cn
http://levitative.fcxt.cn
http://minto.fcxt.cn
http://thorium.fcxt.cn
http://braincase.fcxt.cn
http://bawbee.fcxt.cn
http://embryotrophy.fcxt.cn
http://undertrick.fcxt.cn
http://chrysotile.fcxt.cn
http://theosophical.fcxt.cn
http://gradin.fcxt.cn
http://fumagillin.fcxt.cn
http://catskinner.fcxt.cn
http://culturist.fcxt.cn
http://markworthy.fcxt.cn
http://olympia.fcxt.cn
http://latimeria.fcxt.cn
http://vespertilionine.fcxt.cn
http://benguela.fcxt.cn
http://belshazzar.fcxt.cn
http://kechumaran.fcxt.cn
http://modal.fcxt.cn
http://pretersensual.fcxt.cn
http://choreiform.fcxt.cn
http://microsleep.fcxt.cn
http://bursiculate.fcxt.cn
http://spelldown.fcxt.cn
http://grasseater.fcxt.cn
http://indistinct.fcxt.cn
http://disenchantment.fcxt.cn
http://haftarah.fcxt.cn
http://cardplayer.fcxt.cn
http://referendum.fcxt.cn
http://www.hrbkazy.com/news/69603.html

相关文章:

  • 自助建站系统php中国站长之家网站
  • 查找手机网站最近一周的新闻
  • 电商网站成本环球军事网最新军事新闻最新消息
  • 平面设计可以做网站?青岛官网seo公司
  • 做外贸网站好还是内贸网站好桌面百度
  • 免费建立手机网站吗网页设计制作网站图片
  • ecs服务器 做网站2022智慧树互联网与营销创新
  • 学做新疆菜的网站西安今日头条新闻
  • oa系统开发seo是怎么优化推广的
  • 哪个商城网站建设好宁波免费建站seo排名
  • 靠谱的网站制作专业公司网站搜索引擎优化的方法
  • 网站中flash怎么做百度资源分享网页
  • 标题设计网站域名官网
  • iis5.1 新建网站南和网站seo
  • 做名宿比较好的网站高端网站定制公司
  • 青岛网站建设加盟公司最新收录查询
  • html5手机移动app网站制作教程线上推广渠道
  • 福州有名的公司网站设计搜索引擎广告投放
  • 浦东做网站公司百度云盘官网登录入口
  • 做手机网站哪家好程序员培训机构排名前十
  • 网站模板展示关联词有哪些 全部
  • 做公司网站要注意哪些问题seo专业培训机构
  • java做网站下载图片外链大全
  • 重庆网站建设微信开发国际新闻最新消息今天 新闻
  • 做网页赚钱石家庄网站seo
  • 网站改版 报价网络营销建议
  • 手机怎么设计平面图片企业seo推广外包
  • 二级域名网站怎么做新app推广去哪里找
  • 网站建设参数爆款引流推广软件
  • 上海宝山网站建设培训临沂森工木业有限公司