hdu 2648 Shopping
Shopping
思路:这道题很明显使用容器,此时我们来判断使用什么容器,这道题涉及了不同数据类型的保存,故使用map,正常使用map进行数据的保存,最后利用迭代器比较大小,最后输出。
代码:
#include<iostream> #include<string> #include<map> using namespace std; int main(){ int m, n, i; int rank, num; string s; map<string, int>shop; while (cin >> n){ for (i = 1; i <= n; i++) cin >> s; cin >> m; while (m--){ for (i = 1; i <= n; i++){ cin >> num >> s; shop[s] += num; } rank = 1; map<string, int>::iterator it; for (it = shop.begin(); it != shop.end(); it++) if (it->second>shop["memory"]) rank++; cout << rank << endl; } shop.clear(); } system("pause"); return 0; }