* * Copyright (c) 2012, Computer College of Yantai University
* All rights reserved.
* Author: Liu Tongbin
* Date of Completion: December 05, 2012
* Version number: v1.0
* *
Input Description:
* Problem Description: There are n people in a circle, the order of automatic arranging, starting from the first person to count (from the 1~3 numbered), c9/>* who report 3 exit Circle, ask the last person left in the first date.
* Program output:
* Problem Analysis: slightly
* Algorithm design: Slightly * *
#include <iostream>
using namespace std;
int main ()
{
int num[50];
int i,j,k,m,n;
int *p;
cout<<endl<< "Please enter the total number:" <<endl;
cin>>n;
P=num;
for (i=0;i<n;i++)
{
* (p+i) =i+1; In order of 1 to n, each person is numbered
}
i=0; I for each cycle of the count variable
k=0; K is the count variable m=0 according to 1 2 3 off
; M for the number of exits
while (m<n-1) //When the number of exits is less than n-1 (that is, the number of exits is greater than 1 o'clock) Execute loop body
{
if (* (p+i)!=0)
{
k++;
}
if (k==3) //The exit number is set to 0
{
* (p+i) =0;
k=0;
m++;
}
i++;
if (i==n)
{
i=0;//count to tail I revert to 0
}
} while
(*p==0)
{
p++;
}
cout<< "The last one is the" <<*p<< "number. "<<endl;
return 0;
}