zoukankan      html  css  js  c++  java
  • 3331=数据结构实验之链表八:Farey序列

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 struct node
     4 {
     5     int date1,date2;
     6     struct node*next;
     7 } node;
     8 int main()
     9 {
    10     struct node*p,*head,*end,*q;
    11     head=(struct node*)malloc(sizeof(struct node));
    12     head->next=NULL;
    13     end=head;
    14     int n,i;
    15     scanf("%d",&n);
    16     p=(struct node*)malloc(sizeof(struct node));
    17     p->next=NULL;
    18     q=(struct node*)malloc(sizeof(struct node));
    19     q->next=NULL;
    20     head->next=p;
    21     p->next=q;
    22     q->next=NULL;
    23     p->date1=0;
    24     p->date2=1;
    25     q->date1=1;
    26     q->date2=1;
    27     for(i=1; i<=n; i++)
    28     {
    29         end=head->next;
    30         while(end->next!=NULL)
    31         {
    32             p=end->next;
    33             if((p->date2+end->date2)<=i)
    34             {
    35                 q=(struct node*)malloc(sizeof(struct node));
    36                 q->date1=end->date1+p->date1;
    37                 q->date2=end->date2+p->date2;
    38                 q->next=NULL;
    39                 end->next=q;
    40                 q->next=p;
    41                 end=end->next->next;
    42             }
    43             else
    44             {
    45                 end=end->next;
    46             }
    47         }
    48     }
    49 
    50     p=head->next;
    51     int mark=0;
    52     for(; p!=NULL; p=p->next)
    53     {
    54         if(mark!=0)printf("	");
    55         mark++;
    56         printf("%d/%d",p->date1,p->date2);
    57         if(mark==10)printf("
    "),mark=0;
    58 
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    linux目录结构
    php程序员要懂那些linux知识?
    树和二叉树
    linux学习课程
    顺序栈的实现
    编写一个插件(前面JavaScript高级总结)
    javascript高级课程-4
    字符串的顺序表
    js 万年历实现
    利用 postMessage 进行数据传递 (iframe 及web worker)及问题
  • 原文地址:https://www.cnblogs.com/Angfe/p/11638484.html
Copyright © 2011-2022 走看看