
求解
uj5u.com熱心網友回復:
這是我的代碼,可以參考一下:
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"請問有多少人?"<<endl;
cin>>n;
bool all[n];//all[0]不用
int times=0;
for(auto &a:all)
a=true;
int c=0;
int q;
cout<<"淘汰幾人?"<<endl;
cin>>q;
int p;
cout<<"數到幾淘汰?"<<endl;
cin>>p;
for(int b=0;b<q;++b)
{
while(1)
{
if(c<n)
++c;
else
c=1;
if(all[c])
++times;
if(times%p==0)
{
all[c]=false;
times=0;
break;
}
}
}
for(int a=1;a<=n;++a)
cout<<all[a]<<" ";
return 0;
}
uj5u.com熱心網友回復:
我用#CSDN#這個app發現了有技術含量的博客,小伙伴們求同去《【leetcode】約瑟夫環問題》, 一起來圍觀吧 https://blog.csdn.net/weixin_44155115/article/details/105208422?utm_source=appuj5u.com熱心網友回復:
https://blog.csdn.net/abcd7038/article/details/105382017轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/88701.html
標籤:C++ 語言
上一篇:C++物件和物體
下一篇:C語言求答案
