Bootstrap

小西的排序

#include<stdio.h>
struct building {
	char name[20];
	double h;
};
void sort(struct building s[],int n);//这里的struct building s【】相当于传的指针 
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF){
		struct building s[n];
		for(int i=0;i<n;i++){
			scanf("%s %lf",&s[i].name,&s[i].h);
		}
		sort(s,n);//这里在调用函数 
		for(int i=0;i<n;i++){
			printf("%s ",s[i].name);
		}
		printf("\n");
	}
}
void sort(struct building s[],int n){//这个函数用的还是挺好的(自己想出来的喔 
	struct building temp;//交换媒介也要这个结构类型 
	for(int i=0;i<n-1;i++){
		for(int j=0;j<n-1-i;j++){
			if(s[j].h>s[j+1].h){
				temp=s[j];
				s[j]=s[j+1];
				s[j+1]=temp;
			}
		}
	}	
}

https://oj.gxu.icu/contest/334/problem/5

;