马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
struct people
{
string sex;
double tall;
};
bool cmp(people a,people b)
{
return a.tall<b.tall;
}
int main()
{
int n;
cin>>n;
people num[n];
int m=0,k=0;
double num1[1000],num2[1000];
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
for(int i=0;i<n;i++)
cin>>num[i].sex>>num[i].tall;
for(int i=0;i<n;i++)
{
if(num[i].sex=="male")
{
num1[m]=num[i].tall;
m++;
}
if(num[i].sex=="female")
{
num2[n]=num[i].tall;
n++;
}
}
sort(num1,num1+m);
sort(num2,num2+n,cmp);
for(double &x:num1)
cout<<x<<" ";
for(double &x:num2)
cout<<x<<" ";
cout<<endl;
return 0;
}
error: could not convert '* __it1' from 'double' to 'people'|
sort(num2,num2+n,cmp);
应该和cmp函数参数类型相同吧
|