#include<iostream> using namespace std; struct ka{ string name; int age; string xin; }; int main(){ ka a[5]; ka t; for(int i=0;i<5;i++){ cin>>a[i].name>>a[i].age>>a[i].xin; } for(int i=0;i<5;i++){ for(int j=0;j<5-i;j++){ if(a[j].age>a[j+1].age){ t.age=a[j].age; t.name=a[j].name; t.xin=a[j].xin; a[j].age=a[j+1].age; a[j].name=a[j+1].name; a[j].xin=a[j+1].xin; a[j+1].age=t.age; a[j+1].name=t.name; a[j+1].xin=t.xin; } } } for(int i=0;i<5;i++){ cout<<a[i].name<<" "<<a[i].age<<" "<<a[i].xin<<endl; } return 0; }
标签:ka,name,int,age,xin,冒泡排序 From: https://www.cnblogs.com/As10016/p/17994697