#include<fstream>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
struct Book
{
string Name;
int Year;
int Price;
};
bool CompName(const Book &b1,const Book &b2)
{
if(b1.Name!=b2.Name)
return b1.Name<b2.Name;
else if(b1.Year!=b2.Year)
return b1.Year<b2.Year;
else
return b1.Price<b2.Price;
}
bool CompYear(const Book &b1,const Book &b2)
{
if(b1.Year!=b2.Year)
return b1.Year<b2.Year;
else if(b1.Name!=b2.Name)
return b1.Name<b2.Name;
else
return b1.Price<b2.Price;
}
bool CompPrice(const Book &b1,const Book &b2)
{
if(b1.Price!=b2.Price)
return b1.Price<b2.Price;
else if(b1.Name!=b2.Name)
return b1.Name<b2.Name;
else
return b1.Year<b2.Year;
}
int main()
{
//ifstream cin("acmilan.txt");
vector<Book> v;
Book book;
string sorting;
int n;
int i;
int line=0;
while(cin>>n)
{
if(n==0)
break;
line++;
v.clear();
for(i=0;i<n;i++)
{
cin>>book.Name>>book.Year>>book.Price;
v.push_back(book);
}
cin>>sorting;
if(sorting=="Name")
sort(v.begin(),v.end(),CompName);
else if(sorting=="Year")
sort(v.begin(),v.end(),CompYear);
else if(sorting=="Price")
sort(v.begin(),v.end(),CompPrice);
if(line!=1)
cout<<endl;
for(i=0;i<v.size();i++)
{
cout<<v[i].Name<<" "<<v[i].Year<<" "<<v[i].Price<<endl;
}
}
//system("pause");
return 0;
}
分享到:
相关推荐
zoj 1610 Count the Colors.md
zoj 1255 The Path.md
ZOJ解题报告ZOJ解题报告ZOJ解题报告ZOJ解题报告
zoj 1810 The Gourmet Club.md
zoj 2499 The Happy Worm.md
zoj 2151 The Highest Profits.md
zoj题目简单归类zoj题目简单归类zoj题目简单归类
acm中zoj1002的可运行C++程序
包含了zoj700多道题目的源代码,在做题时可以参考
Problem Arrangement zoj 3777
ZOJ题目答案源码
一个非常非常非常非常实用的zoj结题代码
ZOJ1805代码
学习ACM程序设计的朋友一定要看,这是训练必备的POJ ZOJ题目分类及解题思路
zoj 1003 c语言的,要写这么多描述吗。。
本代码是zoj上AC的1951的代码,把双重循环简化为O(n),不过素数判断的改进还不够
The reason is that when the director chooses the words from the dictionary and encrypts them, he never changes their order (the words in the dictionary are lexicographically sorted). String a1a2 ... ...
zoj1027解题指南和代码,还不错,是学校培训给的。
浙大ZOJ题目分类,可以让你更方便快速锁定那你想要联系的题目,是自己快速提高·
ZOJ题解集合-截至2835。共1244个文件,C/C++,有重复