编程题: 100个数字1~100围成一圈。从1开始,向后数10个数,然后这个数出列, 循环往复,直到最后一个数出

求高手编程 要求有详细代码 谢谢
100个数字1~100围成一圈。从1开始,向后数10个数,然后这个数出列,
循环往复,直到最后一个数出列为止。请写程序给出这100个数的出列顺序
(要求每输出10个数换行)。

结果如下:
10 20 30 40 50 60 70 80 90 100
11 22 33 44 55 66 77 88 99 12
24 36 48 61 73 85 97 9 25 38
52 65 79 93 6 21 37 53 68 83
98 15 。。。。。。
太多数字懒得打了。。。。。大致就是这样的顺序。 求大神!!求程序!

完全符合要求,你可以测试一下

#include <iostream.h>
#include <iomanip.h>
int main()
{
const int n=100;
int m=10;
int a[n];
for(int j=0;j<n;j++)a[j]=j+1;
int k=1;
int i=-1;
while(1)
{

for(int j=0;j<m;)
{
i=(i+1)%n;
if(a[i]!=0)j++;
}
cout<<setw(3)<<a[i]<<" ";
if (k%10==0)cout<<endl;
a[i]=0;
if(k==n)break;
k++;
}
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-27
用什么语言编程啊?
第2个回答  2011-04-27
//没仔细想,就是简单的模拟了一下,貌似复杂度有点高
#include <iostream>
#include <list>

#define MAX_VALUE 100
#define STEP 10

using namespace std;

int main()
{
list<int> l;
for(int i=1;i<=MAX_VALUE;i++)
l.push_back(i);

list<int>::iterator it = l.begin();

int count = 0;
while(l.size() > 1)
{
if(it == l.end())
it = l.begin();
if(count == STEP)
{
count = 1;
list<int>::iterator tmp = it++;
l.erase(tmp);
continue;
}
it++;
count++;

}
cout<<"left number is "<<l.front()<<endl;

return 0;
}
第3个回答  2011-04-27
#include <iostream>
#include <list>

#define MAX_VALUE 100
#define STEP 10

using namespace std;

int main()
{
list<int> l;
for(int i=1;i<=MAX_VALUE;i++)
l.push_back(i);

list<int>::iterator it = l.begin();

int count = 0;
while(l.size() > 1)
{
if(it == l.end())
it = l.begin();
if(count == STEP)
{
count = 1;
list<int>::iterator tmp = it++;
l.erase(tmp);
continue;
}
it++;
count++;

}
cout<<"left number is "<<l.front()<<endl;

return 0;
}
相似回答