多本图书

来源:互联网 发布:php system返回1 编辑:程序博客网 时间:2024/04/30 10:23

#include<stdio.h>
#include<stdlib.h>
struct time
{
 int year;
 int mouth;
 int day;
};
struct book
{
 int a;
 char shuming[30];
 char zuozhe[30];
 char chubanshe[30];
 struct time time;
 double z;
};
void main()
{
 int n, i, j;
 struct book t, *d;
 scanf("%d", &n);
 d=(struct book*)malloc(n*sizeof(struct book));
 for(i=0;i<n;i++)
 {
  scanf("%d %s %s %s %d-%d-%d %lf", &d[i].a, d[i].shuming, d[i].zuozhe, d[i].chubanshe, &d[i].time.year, &d[i].time.mouth, &d[i].time.day, &d[i].z);
 }
 for(i=0;i<n;i++)
 {
  for(j=0;j<n-1;j++)
  {
   if(d[j].a<d[j+1].a)
   {
    d[j]=t;
    d[j]=d[j+1];
    d[j+1]=t;
   }
  }
 }
 printf("编号 书名 作者 出版社 出版日期 价格");
 for(i=0;i<n;i++)
 {
  printf("%d %s %s %s %d年%d月%d日 %.2lf\n", d[i].a, d[i].shuming, d[i].zuozhe, d[i].chubanshe, d[i].time.year, d[i].time.mouth, d[i].time.day, d[i].z);
 }
}
原创粉丝点击