|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include"stdio.h"
- #include"stdlib.h"
- #include"string.h"
- typedef struct Stu
- {
- int num;
- char name[11];
- char sex[10];
- int age;
- int grade;
- }student;
- typedef struct sqlist
- {
- student *elem;
- int len;
- }sqlist;
- void creatseqlist(sqlist *L);
- void printseqlist(sqlist L);
- void sortseqlist(sqlist *L);
- void splitseqlist(sqlist L, sqlist *boy, sqlist *girl);
- void creatseqlist(sqlist *L)
- {
- int i, n;
- L->elem=(student *)malloc(n*sizeof(student));
- scanf("%d", &n);
- (L->len)=n;
- for(i=0;i<n;i++)
- {
- int i;
- scanf("%d %s %s %d %d",&(L->elem[i].num), &(L->elem[i].name), &(L->elem[i].sex), &(L->elem[i].age), &(L->elem[i].grade));
- }
- for(i=0;i<n;i++)
- {
- if(strcmp((L->elem)[i].sex, "1")==0)
- {
- strcpy((L->elem)[i].sex,"男");
- }
- if(strcmp((L->elem)[i].sex, "0")==0)
- {
- strcpy((L->elem)[i].sex,"女");
- }
- }
- }
- void printseqlist(sqlist L)
- {
- int i;
- if((L.len)==0)
- {
- printf("无");
- }
- else
- {
- printf("考生号,姓名,性别,年龄,成绩\n");
- for(i=0;i<(L.len);i++)
- {
- printf("%d,%s,%s,%d,%d\n",(L.elem)[i].num, (L.elem)[i].name, (L.elem)[i].sex, (L.elem)[i].age, (L.elem)[i].grade);
- }
- }
- }
- void sortseqlist(sqlist *L)
- {
- int i, j;
- student temp;
- for(i=0;i<(L->len);i++)
- {
- for(j=i+1;j<(L->len);j++)
- {
- if((L->elem)[i].grade<(L->elem)[j].grade)
- {
- temp=(L->elem)[j];
- (L->elem)[j]=(L->elem)[i];
- (L->elem)[i]=temp;
- }
- if((L->elem)[i].grade==(L->elem)[j].grade)
- {
- if((L->elem)[i].num>(L->elem)[j].num)
- temp=(L->elem)[j];
- (L->elem)[j]=(L->elem)[i];
- (L->elem)[i]=temp;
- }
- }
- }
- }
- void splitseqlist(sqlist L, sqlist *boy, sqlist *girl)
- {
- int j,m,i;
- j=0; m=0;
- boy->elem=(student *)malloc(5*sizeof(student));
- girl->elem=(student *)malloc(5*sizeof(student));
- for(i=0;i<(L.len);i++)
- {
- if(strcmp((L.elem)[i].sex, "男")==0)
- {
- boy->elem[j]=L.elem[i];
- j++;
- }
- if(strcmp((L.elem)[i].sex, "女")==0)
- {
- girl->elem[m]=L.elem[i];
- m++;
- }
-
- }
- boy->len=j;
- girl->len=m;
- }
- int main()
- {
- sqlist L;
- sqlist boy;
- sqlist girl;
- creatseqlist(&L);
- printseqlist(L);
- printf("\n排序后");
- sortseqlist(&L);
- printseqlist(L);
- splitseqlist(L, &boy, &girl);
- printf("男生信息");
- printseqlist(boy);
- printf("女生信息");
- printseqlist(girl);
- return 0;
- }
复制代码
一开始可以运行,后来就运行不了了,哪位大神给我看看 |
|