公司网站怎么自己做,wordpress分类,校园风景网页设计图片,网络服务器管理软件文章目录1. 题目2. 解题1. 题目
描述 公司给你提供了所有员工的信息#xff0c;包括其ID#xff0c;姓名和所属部门。 以及他们之间的朋友关系#xff0c;每个关系中由2个ID组成#xff0c;如 “1, 2” 代表1号员工和2号员工是朋友。 朋友关系不具有传递性#xff0c;即B…
文章目录1. 题目2. 解题1. 题目
描述 公司给你提供了所有员工的信息包括其ID姓名和所属部门。 以及他们之间的朋友关系每个关系中由2个ID组成如 “1, 2” 代表1号员工和2号员工是朋友。 朋友关系不具有传递性即B、C都是A的朋友但B和C不一定是朋友。 请计算每个部门中与其它部门的员工有朋友关系的员工个数。
所有的输入中逗号后都跟有一个空格而且你的程序输出也要和样例格式相同。返回的列表对顺序没有要求。员工信息数量 N 50 条。朋友关系的数量 M 1000 条。员工ID都是100以内的数字。部门数 K 20。示例
输入:
employees [1, Bill, Engineer,2, Joe, HR,3, Sally, Engineer,4, Richard, Business,6, Tom, Engineer
]friendships [1, 2,1, 3,3, 4
]输出:
Engineer: 2 of 3
HR: 1 of 1
Business: 1 of 1说明
样例中Engineer的1号员工和HR的2号员工是朋友关系
Engineer 的3号员工和Business的4号员工是朋友关系
所以Engineer有2个人和其它部门有朋友关系输出Engineer: 2 of 3“。
此外HR部门有1人和其他部门有朋友关系
Business部门有1人和其他部门有朋友关系。https://tianchi.aliyun.com/oj/376506598349105305/389682099890885302
2. 解题
class Solution {
public:/*** param employees: information of the employees* param friendships: the friendships of employees* return: return the statistics*/vectorstring departmentStatistics(vectorstring employees, vectorstring friendships) {// write your code here.unordered_mapstring, int count;unordered_mapstring, string id_dep;for(auto e : employees){vectorstring t split(e);id_dep[t[0]] t[2];count[t[2]];}unordered_mapstring, unordered_setstring p;for(auto f : friendships){vectorstring t split(f);if(id_dep[t[0]] ! id_dep[t[1]]) // 同一个部门的话不能计算{ p[id_dep[t[0]]].insert(t[0]);p[id_dep[t[1]]].insert(t[1]);}}vectorstring ans;for(auto ct : count){int all ct.second;string dep ct.first;int num p[dep].size();ans.push_back(dep : to_string(num) of to_string(all));}return ans;}vectorstring split(string str){vectorstring t;string s;for(auto c : str){if(c ,){t.push_back(s);s ;}else if(c ! )s.push_back(c);}t.push_back(s);return t;}
};我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号Michael阿明一起加油、一起学习进步