zoukankan      html  css  js  c++  java
  • 循环列示例(约瑟夫环问题)

    #include<stdio.h>
    #include
    <stdlib.h>

    typedef 
    struct node* link;
    struct node{int item; link next;};

    int main()
    {  
       
    int i,N,M;
       scanf(
    "%d%d",&N,&M);
       link t
    =malloc(sizeof *t),x=t;
       t
    ->item=1;t->next=t;
       
    for(i=2; i<=N; i++){
             x
    =(x->next=malloc(sizeof *x));
             x
    ->item=i; x->next=t;
           }
           
          
    while(x!=x->next){
               
    for(i=1; i<M; i++) x=x->next;
               x
    ->next=x->next->next;N--;
              
              }
              printf(
    "%d\n",x->item);
          
    return 0;
    }
  • 相关阅读:
    MySQL之pymysql模块
    MySQL之用户管理
    MySQL之正则
    MySQL之流程控制
    MySQL之备份恢复
    MySQL之函数
    安卓 adb命令
    js DOM事件
    js DOM
    js 流程控制语句
  • 原文地址:https://www.cnblogs.com/cpoint/p/2029403.html
Copyright © 2011-2022 走看看