HDU 2648 Shopping【映射/字符串哈希】
发布日期:2021-07-01 02:50:54 浏览次数:2 分类:技术文章

本文共 1670 字,大约阅读时间需要 5 分钟。

Problem Description

Every girl likes shopping, so does dandelion.Now she finds the shop is increasing the price every day because the Spring Festival is coming .She is fond of a shop which is called "memory" . Now she wants to know the rank of this shop’s price after the change of everyday.

Input

One line contians a number n(n <= 10000) , stands for the number of shops.
Then n lines ,each line contains a string (the length is short than 31 and only contains lowercase letters and capital letters.) stands for the name of the shop.
Then a line contians a number m(1<= m <= 50) , stands for the days.
Then m parts , every parts contians n lines, each line contians a number s and a string p , stands for this day, the shop p's price has increased s .

Output

Contains m lines, In the ith line print a number of the shop "memory" ‘s rank after the ith day. We define the rank as: If there are t shops’ price is higher than the "memory" , than its rank is t+1 .

Sample Input

3memorykfcwind249 memory49 kfc48 wind80 kfc85 wind83 memory

Sample Output

12

题意:给出 n 家店铺 m 天的价格增长,输出 "memory" 这家店每天的价格排名。


思路:用 map 容器操作。唯一需要注意的是,有多组测试数据。代码如下:

#include 
using namespace std;const int maxn = 40;char str[maxn]; int main() {
int n, m, price; while (~scanf("%d", &n)) {
unordered_map
shops; for (int i = 1; i <= n; ++i) //输入店铺名字,不用做处理 scanf("%s", str); scanf("%d", &m); while (m--) {
int rank = 1; for (int i = 1; i <= n; ++i) {
scanf("%d%s", &price, str); shops[str] += price; } for (const auto &it : shops) if (it.second > shops["memory"]) ++rank; printf("%d\n", rank); } } return 0;}

另外,还会使用字符串哈希来做这一道题。

转载地址:https://memcpy0.blog.csdn.net/article/details/108347419 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode C++ 剑指 Offer 67. 把字符串转换成整数【字符串】
下一篇:【算法学习】字符串专题 基本操作和字符串哈希

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月24日 09时52分42秒