请问在这个约瑟夫问题中,把数组定义在main()函数前与下面程序中定义的数组方式
有什么异同?
为什么在VC6.0中认为示例程序的数组错误,而在dev C++中却没事
#include <iostream>
#include <iomanip> //调用setw()函数
using namespace std;
//bool str[101];
int main()
{
int n, m;
cin >> n >> m; //n为人数, m为报数数字
bool str[n+1];
cout << endl;
for(int i=1;i<=101;++i)
{
str[i] = false; //相当于memset(str, 0, sizeof(str))
}
int a = 1, s = 1, f=1;
do
{
++a;
if(a==n+1) //模拟环状
a=1;
if(str[a]==false)
++f;
if(f==m)
{
f = 0; //计数器清零
++s;
str[a] = true;
cout << a << setw(5) << endl; //输出并设置域宽
}
}while(s!=n);
return 0;
}