c++的几个问题
注释里有问题:
// Ex_Final_1.cpp : 约瑟夫问题 数组版
// 呆呆蜗牛 aka 天羽云尘
#include <iostream>
using namespace std;
int main( void )
{
const int ARRAY_SIZE = 1000;
// 人数
int number;
int temp;
// 报到skip的人出列
int skip;
// 计数器
int counter = 0;
// 当前位置标记
int loc = -1;
// 是否在圈内标记
bool isInCircle[ ARRAY_SIZE ]; //bool关键字是什么意思?
for ( counter = 0; counter < ARRAY_SIZE; isInCircle[ counter++ ] = true ); //这句话是什么意思?
// 开始输入
cout << "How many people are there in the circle? ";
cin >> number;
temp = number;
cout << "The one counting n will be ejected! Please input n: ";
cin >> skip;
cout << endl;
// 踢人
while ( temp > 1 )
{
counter = 0;
while ( counter < skip )
{
loc = ( loc + 1 ) % number;
if ( isInCircle[ loc ] ) counter++;
}
isInCircle[ loc ] = false; //这里面的false又是什么意思?是表示为0吗?
cout << "Person " << loc + 1 << " is kicked!" << endl;
temp--;
}
cout << endl;
// 判断幸运儿并输出
loc = 0;
while ( !isInCircle[ loc ] ) loc++;
cout << "The lucky dog is Person " << loc + 1 << " !!" << endl;
return 0;
}
匿名
回答:2
人气:11
解决时间:2009-03-30 23:44