前几天做了美团,OPPO的秋招笔试题,然后又做了一场小红书,总体难度我觉得都差不多,涉及到的知识点要么是语法模拟,或者就是一些基础算法,所以这样看秋招编程题还是很简单的,对于笔试我们还要把除了算法题以为的选择题做好,比如我看还有好多MySQL之类的题,好了话不多说,我们来看一下小红书2024秋招后端开发的题,先贴个链接 题目测评链接——
目录
A题
题面

思路分析
首先我们按要求读入每个字符串,然后开一个map统计维护每个字符串的个数,如果该种字符串数量大于等于三,我们就将其放入pair数对里,因为题目中说明了排序输出方式,那我们需要对pair按要求开个cmp排个序就行了——
代码实现
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <climits>
#include <vector>
#define int long long
#define x first
#define y second
using namespace std;
const int N = 1e5 + 10;
typedef pair<string,int> PII;
PII p[N];
bool cmp(const PII &a,const PII &b)
{
if(a.y != b.y) return (a.y > b.y);
else return a.x < b.x;
}
void solve()
{
map<string,int> mp;
string str;
while(cin >> str)
{
mp[str]++;
}
// for(auto &c : mp) cout << c.x << " " << c.y << endl;
int i = 0;
for(auto &c : mp)
{
if(c.y >= 3)
p[i++] = {c.x,c.y};
}
sort(p , p + i ,cmp);
for(int j = 0; j < i; j++) cout << p[j].x << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t = 1;
while(t -- ) solv

最低0.47元/天 解锁文章
631

被折叠的 条评论
为什么被折叠?



