1 条题解
-
0
自动搬运
来自洛谷,原作者为

Temp113
You have full control over the entire world.搬运于
2025-08-24 21:17:48,当前版本为作者最后更新于2025-03-08 17:20:14,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
Solution
若 (存在 ),计入压缩单词中,一开始压缩单词只有第一个字母。
再用 map 对所有压缩单词统计次数,并求出答案。
Code
#include<bits/stdc++.h> using namespace std; const int N = 1e4 + 5; int n, l; string s, ss[N], ans = " "; map<string, int> mp; int main(){ ios::sync_with_stdio(false); cin.tie(); cin >> n; for(int i = 1; i <= n; i++){ ss[i] = ""; cin >> s; l = s.length(); ss[i] += s[0]; for(int j = 1; j < l; j++) if(s[j - 1] != s[j]) ss[i] += s[j]; mp[ss[i]]++; } for(int i = 1; i <= n; i++) if(mp[ss[i]] > mp[ans]) ans = ss[i]; cout << ans; return 0; }
- 1
信息
- ID
- 6661
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 2
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者