[约瑟夫环c语言]用C++编写约瑟夫环(第二次修改)超精简

更新时间:2015-02-21    来源:C语言    手机版     字体:

【www.bbyears.com--C语言】


#include
#include<iostream.h>
typedef struct LNode
{int num,pwd;
struct LNode *next;
}LNode, *LinkList;
void main()
{
 int a,i=1,m,n,j;//m为报数上限值,n为人数,j为输入的密码;
    cout<<"please enter m:";
    cin>>m;
    cout<<"please enter n:";
    cin>>n;
    LinkList head,p,pt;
 while(i<=n)
    {
  pt=new LNode;
  if(i==1)
  {
   p=head=pt;
      cout<<"please enter the password:";
   cin>>j;
         p->num=i;
         p->pwd=j;
   i++;
  }else
  {
   p->next=pt;
      p=pt;
            cout<<"please enter the password:";
   cin>>j;
         p->num=i;
         p->pwd=j;
         i++;
  }
 }p->next=head;
    for(i=1;i<=n;i++)
 {
  for(a=1;a  p=p->next;
     pt=p->next;
     m=pt->pwd;
     cout<num<<"n";
  p->next=pt->next;
  free(pt);
 }
}

本文来源:http://www.bbyears.com/asp/13123.html

猜你感兴趣