[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
掷骰子游戏设计:
假如有n个学生排成一圈,编号从1到n,每个人有初始积分,不防设为100。从1号开始掷骰子,骰子出现后,根据点数减去掷骰人的相应积分,如减去
10*(6 -
投掷点数),然后根据点数多少,就依次向后数掷骰的点数同等数量的人,被数到的最后一个人继续掷骰子,计算积分,依此类推。如果某人掷骰后,其积分小于等于0则出列,余下的人继续按照此法进行游戏,直到剩下最后一个人,为胜利者。要求打印每次出列的人的编号,掷骰子的次数,当前积分。并打印最后胜利者的相应信息。
#include<iostream> #include<stdlib.h> #include <time.h> using namespace std;
int main() { int i,j,n,magic,remind,count;
//n为学生数量,magic为扔骰子的数目,remind为剩下的人数,count为向后数的有效人数 int a[1000],b[1000]; cin>>n;
remind=n; for(i=0;i<n;i++) { a[i]=0; //记录每个学生扔骰子的次数 b[i]=100; //记录每个学生的积分 }
i=0; count=0; magic=0; srand((unsigned)time(NULL)); while(remind>1)
for(j=0;j<n;j++) { if(b[j]==101) continue; if(b[i]<=0) {
cout<<"被淘汰学生的编号为:"<<i+1<<" " <<"该学生扔骰子的次数为:"<<a[i]<<" "
<<"该学生最后的积分为:"<<b[i]<<endl; b[i]=101; remind--; } count++; if(count==magic+1) {
i=j; count=0; magic=rand()%6+1; b[i]=b[i]-10*(6-magic); a[i]++; } }
for(i=0;i<n;i++) if(b[i]!=101) cout<<"最后胜利的学生的编号为:"<<i+1<<" "
<<"该学生扔骰子的次数为:"<<a[i]<<" " <<"该学生最后的积分为:"<<b[i]<<endl; return 0; }