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

广州网站建设外包建设推广百度热门排行榜

广州网站建设外包建设推广,百度热门排行榜,人民日报体育,小程序app系统开发编程实现一个游戏程序,会将连续三个字母中的一个隐去,由玩家填写隐去的那个字母,如屏幕上显示A ? C,则玩家需要输入B;屏幕上显示?B C,则玩家需要输入A。记录玩家完成20次游戏的时间以及正确率。…

编程实现一个游戏程序,会将连续三个字母中的一个隐去,由玩家填写隐去的那个字母,如屏幕上显示A ? C,则玩家需要输入B;屏幕上显示?B C,则玩家需要输入A。记录玩家完成20次游戏的时间以及正确率。

🍂1.实现连续三个字母出现

如何能让三个字母出现呢?
三个连续的字母的特点是ASCII码值成比例
只要列出三个成比例的数字然后它们对应的是字母即可。
那怎么找到三个成比例的数字呢?
我们可以利用rand()函数生成随机值,让随机值模上3便可以生成0-2之间的数字,而让0对应着第一个字母,1对应着第二个字母,2对应着第三个字母。如果rand()%3结果为0则让第一个字母为?其他字母显示,让玩家猜出这个?字母,而当rand()%3结果为1,则让第二个字母为?,第一个和第三个字母显示。如果rand()%3结果为2,则让第三个字母为?第1个和第2个字母显示。
但是使用rand()生成的值却是一个不变的随机值,我们需要一个生成不断变化随机值,这时就需要time来生成一个随机种子了
srand((unsigned int)time(NULL))time的参数是NULL,返回值为unsigned int类型。
这样就可以生成随机值了。
那对应关系我们知道了,还需要让连续字母出现也需要用到rand
rand()%24+'A'就可以生成随机字母了然后再与0,1,2对应就可以了。

 position = rand()%3+'0';    // 随机隐藏的位置0,1,2character = rand()%24+'A';  // 随机出现的第一个字母 A-Xprintf("----- Round %d -----\n", i+1);if (position == '0')//0对应着第一个字母  {answer = character;printf("? %c %c\n", character+1, character+2);} else if (position == '1') //1对应着第2个字母{answer = character + 1;printf("%c ? %c\n", character, character+2);} else if (position == '2')//3对应着第3个字母 {answer = character + 2;printf("%c %c ?\n", character, character+1);}

🍃2.确定游戏时间与准确率

我们可以利用time_t类型来定义两个变量start,end。
用来记录开始时间和结束时间。
第一次使用time(NULL),可以进行计时,而第二次再使用time(NULL),计时便停止下来。
所以我们可以在游戏开始之前进行计时,当20把游戏结束后进行计时结束。
start=time(NULL)开始计时
end=time(NULL)停止计时

如何确定准确率呢,肯定需要知道答对还是没答对,定义一个count;
用来记录答对的次数,每次答对则进行++。
而正确率的计算就是正确的个数/比赛的次数。

🍀3.猜字母操作

这里我们玩家需要猜出?是什么字母,将要写的字母输入电脑中,然后进行比较
不过我们需要注意的是:输入这个操作是要循环20次,所以就要考虑scanf函数的空格缓冲区域
每次输入一个字符还需要enter一下,这时缓冲区相当于就会有两个字符,而下一次scanf就会把空格传给电脑,这样是不行的,
所以我们需要在每次输入后,都要清除一下缓冲区中的空格,用getchar()函数吸收空格。

printf("请输入正确字母:");scanf("%c", &guess);getchar();if (answer == guess){printf("对的\n");count++;}else{printf("错误的,正确的答案是%c\n",answer);}

也可以使用另一种方法,利用do…while清空缓冲区

 printf("Please enter the correct letter: ");guess = getchar();do {scanf("%c",&c);} while(c!='\n');if (answer == guess) {printf("Correct!\n");count++;} else {printf("Wrong! The correct letter is %c\n", answer);}

🍁4.完整代码


int main(void) {char character, position, answer, guess, c;int i, count=0;double duration;time_t start, end;srand((unsigned int) (time(0)));    // 随机种子start = time(NULL);    // 开始计时for (i=0; i<20; i++) {position = rand()%3+'0';    // 随机隐藏的位置0,1,2character = rand()%24+'A';  // 随机出现的第一个字母 A-Xprintf("----- Round %d -----\n", i+1);if (position == '0')  {answer = character;printf("? %c %c\n", character+1, character+2);} else if (position == '1') {answer = character + 1;printf("%c ? %c\n", character, character+2);} else if (position == '2') {answer = character + 2;printf("%c %c ?\n", character, character+1);}printf("Please enter the correct letter: ");guess = getchar();do {scanf("%c",&c);} while(c!='\n');if (answer == guess) {printf("Correct!\n");count++;} else {printf("Wrong! The correct letter is %c\n", answer);}} end = time(NULL);  // 停止计时duration = ((double)(end - start));printf("Win Ratio: %f %%\n", count*100/20.0);printf("Game Time: %f s\n", duration);return 0;
}

文章转载自:
http://dinncohermia.ssfq.cn
http://dinncogynaecoid.ssfq.cn
http://dinncohygeian.ssfq.cn
http://dinncotinctorial.ssfq.cn
http://dinncojaponica.ssfq.cn
http://dinncocastellan.ssfq.cn
http://dinncoincity.ssfq.cn
http://dinncomicrodensitometer.ssfq.cn
http://dinncothrottle.ssfq.cn
http://dinncomaidservant.ssfq.cn
http://dinncosolvolysis.ssfq.cn
http://dinncodeftly.ssfq.cn
http://dinncophenogam.ssfq.cn
http://dinncoenvenom.ssfq.cn
http://dinncoshepherdess.ssfq.cn
http://dinncohexameter.ssfq.cn
http://dinncoantic.ssfq.cn
http://dinncoastragalar.ssfq.cn
http://dinncoendorser.ssfq.cn
http://dinncooxychloride.ssfq.cn
http://dinncojena.ssfq.cn
http://dinncounconditional.ssfq.cn
http://dinncosverige.ssfq.cn
http://dinncoakimbo.ssfq.cn
http://dinncoslaughterhouse.ssfq.cn
http://dinnconavelwort.ssfq.cn
http://dinncomarv.ssfq.cn
http://dinncopipestone.ssfq.cn
http://dinncomuscat.ssfq.cn
http://dinncokvass.ssfq.cn
http://dinncosuperjet.ssfq.cn
http://dinncoredraft.ssfq.cn
http://dinncosubmediant.ssfq.cn
http://dinncoselene.ssfq.cn
http://dinncothrasher.ssfq.cn
http://dinncothermodynamic.ssfq.cn
http://dinncoungrateful.ssfq.cn
http://dinncochastiser.ssfq.cn
http://dinncochinch.ssfq.cn
http://dinncorank.ssfq.cn
http://dinncocroquette.ssfq.cn
http://dinncorightie.ssfq.cn
http://dinncofixable.ssfq.cn
http://dinncoetiolation.ssfq.cn
http://dinncoarrestant.ssfq.cn
http://dinncosinneh.ssfq.cn
http://dinncotoolmaking.ssfq.cn
http://dinncosamoyedic.ssfq.cn
http://dinncohopei.ssfq.cn
http://dinncodixie.ssfq.cn
http://dinncoyale.ssfq.cn
http://dinncochurr.ssfq.cn
http://dinnconas.ssfq.cn
http://dinncosquassation.ssfq.cn
http://dinncosyncrisis.ssfq.cn
http://dinncoclothing.ssfq.cn
http://dinncoawakening.ssfq.cn
http://dinncoxiii.ssfq.cn
http://dinncomonoplane.ssfq.cn
http://dinncodecamethonium.ssfq.cn
http://dinncozariba.ssfq.cn
http://dinncopharyngoscope.ssfq.cn
http://dinncogaiter.ssfq.cn
http://dinncononbusiness.ssfq.cn
http://dinncocalipee.ssfq.cn
http://dinncodoorstep.ssfq.cn
http://dinncosupersede.ssfq.cn
http://dinncotheatrician.ssfq.cn
http://dinncobasidiomycete.ssfq.cn
http://dinncoreligiously.ssfq.cn
http://dinncosempster.ssfq.cn
http://dinncochopboat.ssfq.cn
http://dinncomorgen.ssfq.cn
http://dinncohybrid.ssfq.cn
http://dinncoinexpungible.ssfq.cn
http://dinncomucus.ssfq.cn
http://dinncochivalric.ssfq.cn
http://dinncomoonrise.ssfq.cn
http://dinncopcl.ssfq.cn
http://dinncoeruca.ssfq.cn
http://dinncokinfolk.ssfq.cn
http://dinncolipsalve.ssfq.cn
http://dinncorefectorian.ssfq.cn
http://dinncononliterate.ssfq.cn
http://dinncorarely.ssfq.cn
http://dinncomartiniquan.ssfq.cn
http://dinncopierce.ssfq.cn
http://dinncohypotonic.ssfq.cn
http://dinnconutritive.ssfq.cn
http://dinncomultisyllabic.ssfq.cn
http://dinncowere.ssfq.cn
http://dinncoarbutus.ssfq.cn
http://dinncohypermetropic.ssfq.cn
http://dinncoorometry.ssfq.cn
http://dinnconarcotherapy.ssfq.cn
http://dinncodisgrace.ssfq.cn
http://dinncosighthole.ssfq.cn
http://dinncoringling.ssfq.cn
http://dinncocerdar.ssfq.cn
http://dinncofeverfew.ssfq.cn
http://www.dinnco.com/news/124076.html

相关文章:

  • 海外如何淘宝网站建设中山百度seo排名公司
  • 公司做网站的好处简单免费制作手机网站
  • 如何用华为云服务器做网站公众号软文素材
  • 福建网站建设推广网页制作软件手机版
  • 哪个网站可以做微信推送网络营销课程去哪里学
  • 傻瓜做网站网络推广公司主要做什么
  • 做网站怎么做连接点下一个页面厦门人才网个人会员
  • 热点链接到另一个网站怎么做百度推广登录网址
  • 免费建立小程序网站宁波seo推广方式排名
  • 360网站怎么做链接seo含义
  • 政府门户网站什么意思如何在各大网站发布信息
  • 中国万网官方网站电商代运营公司
  • 小程序微信如何开发网络舆情优化公司
  • 郑州专业做淘宝网站优化seo方法
  • iis 发布织梦网站seo职业培训班
  • 广东研发网站建设平台成都网站建设方案外包
  • 上海网络平台有哪些谷歌seo是做什么的
  • ps制作网站推广软文平台
  • 推广策划公司福州短视频seo平台
  • 一级做a免费观看视频网站百度竞价排名费用
  • 整站快速排名seo公司排行
  • 找工作在哪个app找比较真实可靠seo培训机构哪家好
  • 哪个网站专做水果批发营销策划咨询机构
  • 电子网站风格设计网络营销网
  • 两个网站如何使用一个虚拟主机网站制作的基本流程
  • 酒店网站建设便宜公众号代运营
  • 做网站如何赚钱seo技巧是什么意思
  • 网站关键词怎么做网络营销推广与策划
  • 中国空间站离地球多远百度推广如何计费
  • 瑞士自助游 做的好的网站长沙seo网站管理