#include "StdAfx.h" #include"stdio.h" #include <malloc.h> #define LEN sizeof(struct baoshu) struct baoshu { int num; struct baoshu *next; }; int main() { int m,i; struct baoshu *head,*q,*p; printf("input num:"); scanf("%d",&m);/* 多少个人*/ if ( m % 3 == 0 ) { printf("No number"); return 0; } head=p=q=(struct baoshu*)malloc(LEN); head->num=1; /*第一个人*/ for ( i = 2; i <= m; i++) { /*第几个人num就等于几,从第二个开始*/ p=(struct baoshu*)malloc(LEN); p->num=i; q->next=p; q=p; } p->next=head; /* 尾巴指向头头 */ do { for ( i = 0; i < 2; i++ ) { p = p->next; } q= p; q->next = p->next->next; m--; } while(m>2); /*少余3个的话,终止*/ printf("%d, %d",p->num,p->next->num); /* 打印缀?/ return 1; }