【蓝桥杯】2024.9.22算法赛——灵魂问题\全栈项目小组(C++)
一、灵魂问题
题目

题目分析
1.要求输出一个整数
2.题目在玩脑筋急转弯,关键句子标出来了——糖什么的根本不重要。所以咖啡不加糖,答案是0!!!
代码
#include <iostream>
using namespace std;
int main()
{
cout << 0;
return 0;
}
二、全栈项目小组
题目



题目分析
1.这里采用哈希表(map),以薪资为键,值为包含两个整数的pair,分别表示该薪资下的前端与后端候选人人数
map<int, pair<int, int>>salary_positions;
2.然后遍历简历,按照简历的薪资与前后端更新哈希表
if (position == 'F')
{
salary_positions[salary].first++;
}
else if (position == 'B')
{
salary_positions[salary].second++;
}
3.遍历哈希表,计算同一薪资下可以组成多少全栈项目小组,即同一薪资下的前端候选人与后端候选人中数量较少的一方
for (auto& entry:salary_positions)
{
int f = entry.second.first;
int b = entry.second.second;
sum += min(f, b);
}
代码
#include <iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
long long int n;
map<int, pair<int, int>>salary_positions;
cin >> n;
for (int i = 0; i < n; i++)
{
int salary;
char position;
cin >> salary >> position;
if (position == 'F')
{
salary_positions[salary].first++;
}
else if (position == 'B')
{
salary_positions[salary].second++;
}
}
int sum = 0;
for (auto& entry:salary_positions)
{
int f = entry.second.first;
int b = entry.second.second;
sum += min(f, b);
}
cout << sum;
return 0;
}

浙公网安备 33010602011771号