当前位置:网站首页>AcWing 1944. 记录保存(哈希,STL)
AcWing 1944. 记录保存(哈希,STL)
2022-06-11 10:58:00 【柃歌】
【题目描述】
农夫约翰一直在详细记录奶牛进入牛棚挤奶的情况。
每小时会有一组三头牛进入牛棚产奶,约翰会记录它们的名字。
例如,在 5 5 5小时内,他可能会记录下如下列表,每行对应进入牛棚的一组牛:
BESSIE ELSIE MATILDA
FRAN BESSIE INGRID
BESSIE ELSIE MATILDA
MATILDA INGRID FRAN
ELSIE BESSIE MATILDA
约翰发现同一组奶牛可能会多次出现在他记录的名单中,在上面的例子中,BESSIE ELSIE MATILDA这个组合出现了 3 3 3次(尽管约翰不一定每次都按同样的顺序记录它们的名字)。
请帮助约翰计算进入牛棚次数最多的一组牛的进入次数。
【输入格式】
第一行包含整数 N N N。
接下来 N N N行,每行都包含一组三头牛的名字,每个名字都是一个长度在 1 ∼ 10 1\sim 10 1∼10之间的由大写字母构成的字符串。
【输出格式】
输出进入牛棚次数最多的一组牛的进入次数。
【数据范围】
1 ≤ N ≤ 1000 1≤N≤1000 1≤N≤1000
【输入样例】
5
BESSIE ELSIE MATILDA
FRAN BESSIE INGRID
BESSIE ELSIE MATILDA
MATILDA INGRID FRAN
ELSIE BESSIE MATILDA
【输出样例】
3
【分析】
首先将每组字符串进行排序,那么不同顺序出现的同样的三个字符串排序后一定是唯一的序列,将这个序列存储在vector<string>中。然后我们使用map<vector<string>, int>统计每组序列出现的次数即可。
【代码】
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
map<vector<string>, int> cnt;
int n, res;
int main()
{
cin >> n;
while (n--)
{
vector<string> str(3);
for (int i = 0; i < 3; i++) cin >> str[i];
sort(str.begin(), str.end());
cnt[str]++;
}
for (auto &[k, v] : cnt) res = max(res, v);
cout << res << endl;
return 0;
}
边栏推荐
- Exploration of kangaroo cloud data stack on spark SQL optimization based on CBO
- International multilingual sea mall rebate product automatic matching order source code
- Why is Web3 a game changer for the "creator economy"
- Tu ne peux pas être libre sans richesse?
- IIHS tsp+ annual safety list released: 7 EVs were selected, and there are common problems in pedestrian AEB
- Report on various activity plans of safety month 2022 (28 pages)
- 杰理之BLE 芯片供电范围及防烧芯片措施【篇】
- 使用国产MCU(国民技术 N32G031F8S7) 实现 PWM+DMA 控制 WS2812
- What is the best annuity insurance product in 2022?
- Taking the cooperation between different banks as an example, the construction of small program ecology
猜你喜欢

适配器模式--能不能好好说话?

杰理之获取 BLE OTA 双备份升级(只能用于 4Mbits 以上的芯片)【篇】

云画质助手iApp源码

Use pydub to modify the bit rate of the wav file, and an error is reported: c:\programdata\anaconda3\lib\site packages\pydub\utils py:170: RuntimeWarning:

Iterator mode -- battlefield autumn point

Taking the cooperation between different banks as an example, the construction of small program ecology

Application of volatile in single chip microcomputer

Shi Yigong: I was not interested in research until I graduated from my doctor's degree! I'm confused about the future, and I don't know what to do in the future

Cloud image quality assistant IAPP source code

使用Yolov3训练自己制作数据集,快速上手
随机推荐
(key points of software engineering review) Chapter IV overall design exercises
杰理之获取 BLE 出现电压检测、ADC 检测不准【篇】
如何养成一个好习惯?靠毅力?靠决心?都不是!
使用Yolov3训练自己制作数据集,快速上手
What is the best annuity insurance product in 2022?
MySQL (IX)
Report on various activity plans of safety month 2022 (28 pages)
Why is Web3 a game changer for the "creator economy"
34. find the first and last positions of elements in the sorted array ●●
MWC 2022 lights up the future, and everything serves
Jerry's acquisition of ble voltage detection and ADC detection inaccuracy [chapter]
杰理之获取 BLE 区分复位跟唤醒【篇】
string类的常见构造及容量操作
封装组件系列-(一)-插槽及动态组件
MN梦奈宝塔主机系统V1.5版本发布
Tu ne peux pas être libre sans richesse?
White screen time, first screen time
VOC格式数据集转yolo格式数据集的方法
34. 在排序数组中查找元素的第一个和最后一个位置 ●●
MySQL download, installation and use - complete and detailed steps