作者在 2009-05-11 22:52:13 发布以下内容
#include<iostream>
#include<algorithm>
using namespace std;
struct ShangPin
{
char name[1000];
float price;
}good[5];
bool comp(ShangPin a, ShangPin b)
{
return a.price < b.price;
}
int main()
{
int i;
for( i = 0; i < 5; i ++)
{
scanf("%s %f",good[i].name, &good[i].price);
}
sort(good, good + 5,comp);
for( i = 0; i < 5; i ++)
{
printf("%s %f\n",good[i].name, good[i].price);
}
return 0;
}
#include<algorithm>
using namespace std;
struct ShangPin
{
char name[1000];
float price;
}good[5];
bool comp(ShangPin a, ShangPin b)
{
return a.price < b.price;
}
int main()
{
int i;
for( i = 0; i < 5; i ++)
{
scanf("%s %f",good[i].name, &good[i].price);
}
sort(good, good + 5,comp);
for( i = 0; i < 5; i ++)
{
printf("%s %f\n",good[i].name, good[i].price);
}
return 0;
}