#include<iostream>
#include<map>
#include<cstdlib>
#include<cstdio>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream inFile("C:\\Users\\DELL\\Desktop\\input.txt",ios::in);
multimap<string, string> authors;
string Name, Book;
while (inFile>>Name >> Book){
authors.insert(make_pair(Name, Book));
}
cout << "请输入要查询的作家: ";
string Author;
cin >> Author;
while (1){
auto it = authors.find(Author);
while (it == authors.end()){
cout << "对不起!您要查询的作家不存在,请重新输入:";
cin >> Author;
it = authors.find(Author);
}
cout << authors.count(Author) << endl;
while (it != authors.end()){
cout << it->first << " " << it->second << endl;
it++;
if (it == authors.end() || (it->first != Author))
break;
}
cout << "如果您想继续查询其他作家的作品,请选择1。" << endl << "如果您想结束查询,请选择0,谢谢!" << endl;
int a;
cin >> a;
if (a == 0){
cout << "谢谢您的光临,欢迎下次再来!" << endl;
break;
}
else{
cout << "请输入要查询的作家: ";
cin >> Author;
}
}
inFile.close();
system("pause");
return 0;
}
multimap 作家与作品查询系统
最新推荐文章于 2021-09-02 13:24:53 发布