#include <iostream>
#include <string>
#include "stdio.h"
#include <iomanip>
using namespace std;
struct picture{
string gender;
float high;
};
int main()
{
int n;
picture a[1001];
double male[1001], female[1001];
int malen, femalen;
malen = femalen = 0;
std::cin >> n;
for(int i = 0; i < n; i++)
{
std::cin >> a[i].gender;
std::cin >> a[i].high;
//male female
if(a[i].gender == "male"){
male[malen] = a[i].high;
malen++;
}
else if(a[i].gender == "female"){
female[femalen] = a[i].high;
femalen++;
}
}
/*
6
male 1.72
male 1.78
female 1.61
male 1.65
female 1.70
female 1.56
*/
for(int i = 0; i < malen; i++)
for(int j = i; j < malen; j++)
if(male[i] > male[j])
swap(male[i], male[j]);
for(int i = 0; i < femalen; i++)
for(int j = i; j < femalen; j++)
if(female[i] < female[j])
swap(female[i], female[j]);
for(int i = 0; i < malen; i++)
std::cout << std::fixed << std::setprecision(2) << male[i] << " ";
for(int i = 0; i < femalen; i++)
std::cout << std::fixed << std::setprecision(2) << female[i] << " ";
cout << endl;
printf("
");
return 0;
}
std::
其实没什么用,要是不要std::
就必须写上
using namespace std;
struct 是一个结构体
有一个int类型变量
和一个string类型变量。