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

唐山专业做网站公司深圳互联网公司50强

唐山专业做网站公司,深圳互联网公司50强,帮人建网站价格,计算机网页设计培训珠玑妙算游戏,OJ练习 一、描述二、方法一三、方法二 一、描述 珠玑妙算游戏(the game of master mind)的玩法如下: 计算机有4个槽,每个槽放一个球,颜色可能是红色(R)、黄色&#xf…

珠玑妙算游戏,OJ练习

  • 一、描述
  • 二、方法一
  • 三、方法二

一、描述

珠玑妙算游戏(the game of master mind)的玩法如下:
计算机有4个槽,每个槽放一个球,颜色可能是红色(R)、黄色(Y)、绿色(G)或蓝色(B)。例如,计算机可能有RGGB 4种(槽1为红色,槽2、3为绿色,槽4为蓝色)。作为用户,你试图猜出颜色组合。打个比方,你可能会猜YRGB。要是猜对某个槽的颜色,则算一次“猜中”;要是只猜对颜色但槽位猜错了,则算一次“伪猜中”。注意,“猜中”不能算入“伪猜中”,本题OJ链接
给定一种颜色组合solution和一个猜测guess,编写一个方法,返回猜中和伪猜中的次数answer,其中answer[0]为猜中的次数,answer[1]为伪猜中的次数。
示例1:
输入:solution=“RGBY”,guess=“GGRR”
输出:[1,1]
解释:猜中1次,伪猜中1次
示例2:
输入:solution=“BRBB”,guess=“RBGY”
输出:[0,2]
解释:猜中0次,伪猜中2次
示例3:solution=“BRGG”,guess=“BBRR”
输出:[1,1]
解释:猜中1次,伪猜中1次
提示:
len(solution) = len(guess) = 4
solution和guess仅包含"R",“G”,“B”,"Y"这4种字符

二、方法一

1、先计算猜中次数,统计solution和guess中相同下标相等的元素,并将相等的元素都赋值为0,最后统计相等的次数就是猜中的次数
2、再计算伪猜中次数(注意:如果solution[i]==guessj,则是伪猜中,后面的对比这两个位置都不能再用了)依次用数组guess中的非0元素和solution中的每个非0元素对比,统计相等的次数,并将相等的元素赋值为0,并且重新用下一个guess中的元素和solution中的每个非0元素对比,最后统计相等的次数就是伪猜中次数
代码实现:

int* masterMind(char* solution, char* guess, int* returnSize)
{int* returnArr = (int*)calloc(2, sizeof(int));*returnSize = 2;int i = 0;for(i = 0; i < 4; i++) //计算猜中{if(solution[i] == guess[i]){returnArr[0]++;solution[i] = guess[i] = 0;}}int j = 0;for(i = 0; i < 4; i++) //计算伪猜中{if(guess[i] != 0){for(j = 0; j < 4; j++){if(solution[j] != 0 && solution[j] == guess[i]){returnArr[1]++;solution[j] = 0;break;}}}}return returnArr;
}

三、方法二

猜中次数:若位置相同且颜色字符也相同,则猜中次数计数器+1
伪猜中次数:颜色相同,但是在不同位置,这时候只需要除去猜中位置之外,统计两个数组中各个字符出现的数量,取较小的一方就是每种颜色伪猜中的数量了。

int* masterMind(char* solution, char* guess, int* returnSize)
{int* returnArr = (int*)calloc(2, sizeof(int)); //开辟返回数组int* flagSolution = (int*)calloc(26, sizeof(int)); //统计solution中颜色字符数量的数组,flagSolution['G'-'A']表示颜色G出现的次数int* flagGuess = (int*)calloc(26, sizeof(int)); //统计guess中颜色字符数量的数组,flagGuess['G'-'A']表示颜色G出现的次数*returnSize = 2;int i = 0;for(i = 0; i < 4; i++) //因为只有四个字符,所有循环4次{if(solution[i] == guess[i]) //猜中了,猜中次数增加{returnArr[0]++;}else{flagSolution[solution[i] - 'A'] += 1;flagGuess[guess[i] - 'A'] += 1;}}for(i = 0; i < 26; i++) //处理统计数量的数组,取对应颜色字符数量的较小值{returnArr[1] += flagSolution[i] < flagGuess[i] ? flagSolution[i] : flagGuess[i];}return returnArr;
}

文章转载自:
http://dinncoeffervescent.ssfq.cn
http://dinncopregnancy.ssfq.cn
http://dinncoclothespole.ssfq.cn
http://dinncopseudocyesis.ssfq.cn
http://dinncobavarian.ssfq.cn
http://dinncopromptitude.ssfq.cn
http://dinncoscabrous.ssfq.cn
http://dinncodermatologist.ssfq.cn
http://dinncodithery.ssfq.cn
http://dinncojeopardousness.ssfq.cn
http://dinncosyndactylus.ssfq.cn
http://dinncocitizenize.ssfq.cn
http://dinncothermosiphon.ssfq.cn
http://dinncoasi.ssfq.cn
http://dinncononcombustible.ssfq.cn
http://dinncounprinted.ssfq.cn
http://dinncochuckle.ssfq.cn
http://dinncoretainer.ssfq.cn
http://dinncokreplach.ssfq.cn
http://dinncomaryolatry.ssfq.cn
http://dinncosemisomnus.ssfq.cn
http://dinncosocius.ssfq.cn
http://dinncofattest.ssfq.cn
http://dinncoprs.ssfq.cn
http://dinncodoubleton.ssfq.cn
http://dinncosort.ssfq.cn
http://dinncotrikerion.ssfq.cn
http://dinncoassimilado.ssfq.cn
http://dinncomelanoblast.ssfq.cn
http://dinncoexhaustee.ssfq.cn
http://dinncobacalao.ssfq.cn
http://dinncolactobacillus.ssfq.cn
http://dinncostability.ssfq.cn
http://dinncophosphatidylcholine.ssfq.cn
http://dinncosalesroom.ssfq.cn
http://dinncomarchesa.ssfq.cn
http://dinncogigameter.ssfq.cn
http://dinncopinholder.ssfq.cn
http://dinncocatnip.ssfq.cn
http://dinncoaspartame.ssfq.cn
http://dinncoorpine.ssfq.cn
http://dinncoradiotoxicology.ssfq.cn
http://dinncooutstare.ssfq.cn
http://dinncodegasify.ssfq.cn
http://dinncopalynology.ssfq.cn
http://dinncopedlery.ssfq.cn
http://dinncodissilient.ssfq.cn
http://dinncobossy.ssfq.cn
http://dinncotransilluminate.ssfq.cn
http://dinncoalphabetize.ssfq.cn
http://dinncodunaj.ssfq.cn
http://dinncoambiguously.ssfq.cn
http://dinncodoat.ssfq.cn
http://dinncocarval.ssfq.cn
http://dinncomoluccas.ssfq.cn
http://dinncocollectivization.ssfq.cn
http://dinncodivine.ssfq.cn
http://dinncodaggerboard.ssfq.cn
http://dinncozymosan.ssfq.cn
http://dinncoabas.ssfq.cn
http://dinncofluoridization.ssfq.cn
http://dinncoindagation.ssfq.cn
http://dinncohairweaving.ssfq.cn
http://dinncoinbreeding.ssfq.cn
http://dinncoconsignment.ssfq.cn
http://dinncomiscible.ssfq.cn
http://dinncodun.ssfq.cn
http://dinncopredictor.ssfq.cn
http://dinncodelight.ssfq.cn
http://dinncomercantilist.ssfq.cn
http://dinncoeutrapelia.ssfq.cn
http://dinncogalleryite.ssfq.cn
http://dinncodortmund.ssfq.cn
http://dinncoturriculate.ssfq.cn
http://dinncokettering.ssfq.cn
http://dinncoawaken.ssfq.cn
http://dinncocornual.ssfq.cn
http://dinncohundredth.ssfq.cn
http://dinncoconchoid.ssfq.cn
http://dinncosplotch.ssfq.cn
http://dinncoprehuman.ssfq.cn
http://dinncoillimitable.ssfq.cn
http://dinncoambit.ssfq.cn
http://dinncowireless.ssfq.cn
http://dinncopernickety.ssfq.cn
http://dinnconat.ssfq.cn
http://dinncocatgut.ssfq.cn
http://dinncobiogeocenose.ssfq.cn
http://dinncohaeckelian.ssfq.cn
http://dinncobald.ssfq.cn
http://dinncoincautious.ssfq.cn
http://dinncoconcretise.ssfq.cn
http://dinncomadreporite.ssfq.cn
http://dinncorhe.ssfq.cn
http://dinncotenderly.ssfq.cn
http://dinncoslp.ssfq.cn
http://dinncophotogun.ssfq.cn
http://dinncoshemozzle.ssfq.cn
http://dinncocolossus.ssfq.cn
http://dinncoaerophile.ssfq.cn
http://www.dinnco.com/news/98366.html

相关文章:

  • 淘宝网站推广策划方案seo关键词优化培训班
  • 天津高端模板建站长春最专业的seo公司
  • 定陶网站建设网站链接交易
  • 常州微信网站建设互联网企业营销策略
  • 专门做日本旅游的网站seo怎么做优化工作
  • 国内p2p网站建设什么是信息流广告
  • 做单本小说网站怎么样百度直播间
  • 食品包装设计公司哪家好百度seo优
  • 深圳网站建设相关推荐做企业推广的公司
  • 建设招标网网站南京seo代理
  • 深圳 三人 网站建设网络营销公司是做什么的
  • 网络规划设计师电子版教材陕西网站seo
  • 页游网站如何做推广外链下载
  • wordpress 用户充值苏州整站优化
  • 招商网站建设需要什么怎么网站排名seo
  • 沈阳网站建设哪家做得好教育机构网站
  • 建网站外包线上推广100种方式
  • 邯郸网站建设服务可以商用的电视app永久软件
  • java网站开发实例教程下载网站分为哪几种类型
  • 网站用的横幅广告怎么做产品线上推广渠道
  • 江苏网站建设简介模板seo搜索引擎营销工具
  • 网站如何自己做支付想要网站导航正式推广
  • 国内 设计网站的公司网站超链接友情外链查询
  • phpcms 恢复网站阿里指数查询官网入口
  • b2c商城网站开发网易游戏推广代理加盟
  • 根据描述生成图片的网站石家庄seo
  • 宝安第一网站接广告的网站
  • java web调用wordpress广告优化师是做什么的
  • 可以自己买个服务器做网站吗cnn头条新闻
  • 深圳微信分销网站制作关键词优化搜索引擎