• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MKT-porter
博客园    首页    新随笔    联系   管理    订阅  订阅
reLeetCode 热题 100-2 字母异位词分组 扩展

1 字符排序

#include <iostream>
#include <algorithm> // for std::sort
#include <string>

int main() {
    std::string str = "programming";
    
    // 对字符串中的字符进行排序
    std::sort(str.begin(), str.end());
    
    std::cout << "排序后的字符串: " << str << std::endl;
    // 输出: aggimmnoprr
    
    return 0;
}

  

2 学生成绩系统 multimap

image

 

#include <iostream>
#include <map>
#include <vector>
#include <string>

int main() {
    std::multimap<std::string, std::pair<std::string, int>> studentRecords;
    
    // 添加学生记录(班级,{姓名,分数})
    studentRecords.insert({"ClassA", {"Alice", 85}});
    studentRecords.insert({"ClassB", {"Bob", 90}});
    studentRecords.insert({"ClassA", {"Charlie", 78}});
    studentRecords.insert({"ClassA", {"David", 92}});
    
    // 查询ClassA的所有学生
    std::cout << "Students in ClassA:" << std::endl;
    auto range = studentRecords.equal_range("ClassA");
    for (auto it = range.first; it != range.second; ++it) {
        std::cout << it->second.first << ": " << it->second.second << std::endl;
    }
    
    return 0;
}

  

posted on 2025-09-10 23:54  MKT-porter  阅读(4)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3