#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct py{
float sg;
string xb;
};
bool c(int a,int b)
{
return a>b;
}
int main()
{
string man;
string woman;
py s1[1000]={0},s2[1000]={0};
int n,y=0,x=0;
cin>>n;
int i;
py a[1000];
for(i=0;i<n;i++)
{
cin>>a[i].xb>>a[i].sg;
if(a[i].xb=='male')
a[i].xb=1;
else
a[i].xb=0;
}
for(i=0;i<n;i++)
{
if(a[i].xb==1)
{
man=a[i].xb;
s1[i]=a[i].sg;
y++;
}
else
{
woman=a[i].xb;
s2[i]=a[i].sg;
x++;
}
}
sort(s1,s1+y)
sort(s2,s2+y,c)
for(i=0;i<n;i++)
{
cout<<s1<<s2;
}
return 0;
}
题目发出来,目前看到的错误是25行字符串要用双引号
#include<iostream>
#include<set>
struct student
{
double height;
bool sex;
};
bool operator<(const student& a, const student& b)
{
return a.height < b.height;
}
bool operator>(const student& a, const student& b)
{
return a.height > b.height;
}
int main()
{
int n;
std::cin >> n;
std::multiset<student, std::less<student>>men;
std::multiset<student, std::greater<student>>women;
while (n--)
{
student s;
std::string str;
std::cin >> str >> s.height;
s.sex = (str == "male");
if (s.sex)
men.insert(s);
else
women.insert(s);
}
for (const student& stu : men)
printf("%.2lf ", stu.height);
for (const student& stu : women)
printf("%.2lf ", stu.height);
return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!