#include <iostream>
#include <bits/stdc++.h>
using namespace std;
/*
现在她想知道这家店的价格在每天变化之后的排名。
InputOne行包含一个数字n (n<=10000),表示商店的数量。
然后n行,每行包含一个字符串(长度小于31且只包含小写字母和大写字母),代表商店的名称。
然后一行包含一个数字m (1<=m<=50),代表天数。
然后是m个零件,每个零件包含n行,每行包含一个数字s和一个字符串p,表示这一天,商店p的价格增加了s. outputcontains m行,在第i行打印该店“内存”在第i天之后的排名。
我们定义秩为:如果有t家店铺的价格高于“内存”,则其秩为t+1。
3
memory
kfc
wind
2
49 memory
49 kfc
48 wind
80 kfc
85 wind
83 memory
1
2
*/
int main()
{
int n;
while (cin >> n)
{
map<string, int> shop;
//初始化商店价格
for(int i=0;i<n;++i)
{
string s;
cin >> s;
shop[s] = 0;
}
int m;
cin >> m;
while (m--)
{
//每天变化
for (int i = 0; i < n; ++i)
{
int price;
string s;
cin >> price >> s;
shop[s] += price;
}
int rank = 1;
int Price = shop["memory"];
for (auto it = shop.begin(); it != shop.end(); it++)
{
if (it->second > Price) rank++;
}
cout << rank << endl;
}
}
return 0;
}
这道题最开始一直wrong,后来发现测试用例不止一个 ,加上while(cin>>n)就好了,
商店对应着价格 根据一天价格浮动得出排名 乍一看可能用struct自定义类型+优先队列实现,但元素是动态变化的,堆不能实现自动排序 ,只能在插入的时候排序,所以老老实实使用map记录,最后遍历得到当天rank