数据结构D1作业

#include<stdio.h>

#include<string.h>

typedef struct stu

{

char name[20];

double height;

int score;

}stu,*stu_p;

int main(int argc, const char *argv[])

{

int i=0;

int j=0;

char temp_name[20]="";

int temp_score=0;

double temp_height=0;

stu arr[7]={};

stu_p p=arr;

for(i=0;i<7;i++)

{

printf("请输入学生姓名>>");

scanf("%s",(p+i)->name);

printf("请输入学生身高>>");

scanf("%lf",&((p+i)->height));

printf("请输入学生成绩>>");

scanf("%d",&((arr+i)->score));

}

for(i=0;i<6;i++)

{

for(j=0;j<6-i;j++)

{

if((*(p+j)).score>(*(p+j+1)).score)

{

temp_score=(*(p+j)).score;

(*(p+j)).score=(*(p+j+1)).score;

(*(p+j+1)).score=temp_score;

temp_height=(*(p+j)).height;

(*(p+j)).height=(*(p+j+1)).height;

(*(p+j+1)).height=temp_height;

strcpy(temp_name,(p+j)->name);

strcpy((p+j)->name,(p+j+1)->name);

strcpy((p+j+1)->name,temp_name);

}

}

}

for(i=0;i<7;i++)

{

printf("%d\t",(*(p+i)).score);

}

printf("\n");

return 0;

}

相关推荐
无限进步_2 小时前
二叉搜索树完全解析:从概念到实现与应用场景
c语言·开发语言·数据结构·c++·算法·github·visual studio
爱写代码的倒霉蛋4 小时前
2022年天梯赛L1-8真题解析(哈希+排序)
数据结构·算法
代码中介商4 小时前
顺序表完全指南:从原理到实现
数据结构·顺序表
澈2074 小时前
C++ list容器完全指南
数据结构·c++·链表
承渊政道5 小时前
【动态规划算法】(完全背包问题从状态定义到空间优化)
数据结构·c++·学习·算法·leetcode·动态规划·哈希算法
爱写代码的倒霉蛋5 小时前
2023年天梯赛L1-8
数据结构·算法
上弦月-编程7 小时前
C语言指针超详细教程——从入门到精通(面向初学者)
java·数据结构·算法
莫等闲-7 小时前
代码随想录一刷记录Day44——leetcode1143.最长公共子序列 53. 最大子序和
数据结构·c++·算法·leetcode·动态规划
承渊政道7 小时前
【动态规划算法】(背包问题经典模型与解题套路)
数据结构·c++·学习·算法·leetcode·动态规划·哈希算法
我头发多我先学7 小时前
C++ 红黑树:从规则到实现,手把手带你写一棵红黑树
数据结构·c++·算法