【Map】HDU-2648 Shopping

在这里插入图片描述

注解

1、熟练使用STL中的Map。
2、对应结果再暂存到数组中,然后从数组中查找有几个比Memory价格高的。

代码

#include <iostream>
#include <map>

using namespace std;

int main() {

    int n;
    
    while(cin>>n) {
        int a[n];
        map<string, int> mp;

        for(int i=0; i<n; i++) {
            string s;
            cin>>s;
            mp[s] = 0;
        }

        int day;
        cin>>day;

        for(int i=0; i<day; i++) {
            int ans = 1;
            for(int j=0; j<n; j++) {
                int tmp;
                string tmpstr;
                cin>>tmp>>tmpstr;
                mp[tmpstr]+=tmp;
                a[j] = mp[tmpstr];
            }
            for(int j=0; j<n; j++) {
                if(a[j]>mp["memory"]) {
                    ans++;
                }
            }
            cout<<ans<<endl;
        }
    }

    return 0;
}

结果

在这里插入图片描述

发布了475 篇原创文章 · 获赞 19 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/zhanggirlzhangboy/article/details/103703463