1022. Digital Library (30) @ PAT (Advanced Level) Practise
2013-08-28 13:37
495 查看
考察倒排索引
from:
http://blog.csdn.net/sunbaigui/article/details/8657103
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<map> #include<sstream> using namespace std; int main() { int n; while(scanf("%d",&n)!=EOF) { //build map map<string,std::vector<string>> queryMap[5]; while(n--) { getchar(); string id, title, author, wordList, publisher, year; getline(cin, id); getline(cin, title); getline(cin, author); getline(cin, wordList); getline(cin, publisher); cin>>year; queryMap[0][title].push_back(id); queryMap[1][author].push_back(id); queryMap[3][publisher].push_back(id); queryMap[4][year].push_back(id); istringstream istr(wordList); while(!istr.eof()) { string word; istr>>word; queryMap[2][word].push_back(id); } } //sort first for(int i = 0; i < 5; ++i) { map<string,std::vector<string>>::iterator it; for(it=queryMap[i].begin(); it!=queryMap[i].end(); it++) sort(it->second.begin(), it->second.end()); } //query int m; scanf("%d",&m); while(m--) { int index; string q; scanf("%d: ", &index); getline(cin, q); printf("%d: ", index); cout<<q<<endl; index--; map<string,std::vector<string>>::iterator it; it = queryMap[index].find(q); if(it!=queryMap[index].end()) { std::vector<string> result = queryMap[index][q]; for(int i = 0; i < result.size(); ++i) cout<<result[i]<<endl; } else printf("Not Found\n"); } } return 0; }
from:
http://blog.csdn.net/sunbaigui/article/details/8657103
相关文章推荐
- PAT (Advanced Level) Practise 1022. Digital Library (30)
- PAT (Advanced Level) Practise 1022 Digital Library (30)
- 1022. Digital Library (30)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1022 Digital Library (30)
- PAT (Advanced Level) Practise 1022. Digital Library (30)
- PAT (Advanced Level)1022. Digital Library (30) vector c_str()
- PAT (Advanced Level) 1022. Digital Library (30)
- 浙大 PAT Advanced level 1022. Digital Library (30)
- 【PAT】【Advanced Level】1022. Digital Library (30)
- 【PAT Advanced Level】1022. Digital Library (30)
- PAT (Advanced Level) 1022. Digital Library (30) 数字图书馆 map
- 1080. Graduate Admission (30)【排序】——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1080 Graduate Admission (30)
- PAT (Advanced Level) Practise 1004. Counting Leaves (30)
- PAT (Advanced Level) Practise 1053 Path of Equal Weight (30)
- PAT (Advanced Level) Practise 1018. Public Bike Management (30)
- PAT (Advanced Level) Practise 1131 Subway Map (30)
- PAT (Advanced Level) Practise 1107. Social Clusters (30) 并查集
- PAT (Advanced Level) Practise 1111 Online Map (30)
- 1026. Table Tennis (30)【排序+模拟+逻辑复杂】——PAT (Advanced Level) Practise