轻松的编程学习
首页
题库
学习路径
在线商城
能力地图
下载应用
登录 / 注册
菜单
找出朋友最多的那个人
👁️ 0 人浏览
💬 0 人评论
❤️ 添加收藏
补全
most_friends
:返回邻居最多的那个人的名字。
(本题用
g++ -std=c++17 -O0
编译。)
提交你的答案
请登录后提交答案。
去登录
← 谁的朋友最多
找出一个人都不认识的 →
更多题目
改成"你好,有词"
输出"100 分"
把年龄改成 20
输出学习天数 30
修复:给文字加引号
修复:补上右括号
代码编辑器
语言:
python3
c11
cpp17
Ctrl
+
Enter
运行
👩🏫 AI
▶ 运行代码
重置代码
打印代码
#include <iostream> #include <string> #include <utility> #include <vector> using namespace std; // 五个人:0 阿岚、1 小满、2 阿泰、3 南风、4 北辰 const vector<string> NAMES = {"阿岚", "小满", "阿泰", "南风", "北辰"}; // 四段关系(无向):阿岚-小满、阿岚-阿泰、小满-阿泰、阿泰-南风 const vector<pair<int, int>> EDGES = {{0, 1}, {0, 2}, {1, 2}, {2, 3}}; int id_of(const string& name) { for (int i = 0; i < (int)NAMES.size(); i++) { if (NAMES[i] == name) return i; } return -1; } vector<vector<int>> build_adj() { vector<vector<int>> adj(NAMES.size()); for (auto [a, b] : EDGES) { adj[a].push_back(b); adj[b].push_back(a); } return adj; } string most_friends(const vector<vector<int>>& adj) { // TODO: 扫一遍所有人,挑出邻居数组最长的那个 return ""; } int main() { cout << most_friends(build_adj()) << endl; }
本次输入:
输出:
👩🏫
AI
请登录后使用 AI 老师
×
登录后可获得解题思路、提示与错误分析。
去登录
关闭
🎉
恭喜你,回答正确!
系统判定:正确
我知道了
💬 题目评论
提交
全部评论
全部评论