首页 > 学院 > 开发设计 > 正文

1022. Digital Library (30)

2019-11-11 05:05:54
字体:
来源:转载
供稿:网友

map<string,vector<string>>来存储各个条件下的id,输入完成后,对要输出的map的second即vector进行排序,然后输出即可 对于关键词先getline读取一行,然后用stringstream重新输入到string 如果用int来存储id的话,输出的时候000000显示为0,输出需要设置格式

#include<iostream>#include<sstream>#include<string>#include<map>#include<vector>#include<algorithm>using namespace std;#PRagma warning (disable:4996)map<string, vector<string>> one, two, three, four, five;int main(){ //freopen("0.txt", "w", stdout); int N; cin >> N; for (int t = 0;t < N;t++) { string id; cin >> id; getchar(); string str; getline(cin, str); one[str].push_back(id); getline(cin, str); two[str].push_back(id); stringstream ss; getline(cin, str); ss.str(str); while (!ss.eof()) { ss >> str; three[str].push_back(id); } getline(cin, str); four[str].push_back(id); getline(cin, str); five[str].push_back(id); } cin >> N; getchar(); for (int t = 0;t < N;t++) { string str,str2; getline(cin, str); str2.insert(str2.end(),str.begin() + 3, str.end()); cout << str<<endl; switch (str[0]) { case '1': if (one[str2].empty()) cout << "Not Found" << endl; sort(one[str2].begin(), one[str2].end()); for (auto x : one[str2]) cout << x << endl; break; case '2': if (two[str2].empty()) cout << "Not Found" << endl; sort(two[str2].begin(), two[str2].end()); for (auto x : two[str2]) cout << x << endl; break; case '3': if (three[str2].empty()) cout << "Not Found" << endl; sort(three[str2].begin(), three[str2].end()); for (auto x : three[str2]) cout << x << endl; break; case '4': if (four[str2].empty()) cout << "Not Found" << endl; sort(four[str2].begin(), four[str2].end()); for (auto x : four[str2]) cout << x << endl; break; case '5': if (five[str2].empty()) cout << "Not Found" << endl; sort(five[str2].begin(), five[str2].end()); for (auto x : five[str2]) cout << x << endl; break; } }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表