实用指南:【代码】牛客:HJ26 字符串排序[华为机考][map]

学习要点

  1. multimap.equal_range

题目链接

字符串排序_牛客题霸_牛客网

题目描述

解法:multimap

#include
#include
#include
#include
using namespace std;
int main() {
string line_big_str;
getline(cin,line_big_str);
multimap> ch_bool_pos_map;
vector ret_ch(line_big_str.size(),'a');
for(int i = 0;i tv;
tv.push_back(1); tv.push_back(i);
// 构造键值对:小写字母
ch_bool_pos_map.insert({line_big_str[i],tv});
}
else if(isupper(line_big_str[i]))
{
// 构造值数组
vector tv;
tv.push_back(0); tv.push_back(i);
// 构造键值对:大写字母
ch_bool_pos_map.insert({tolower(line_big_str[i]),tv});
}
else {
// 确定非字母字符位置
ret_ch[i] = line_big_str[i];
}
}
// 写入ret_ch
vector t_ret;
for(char ch = 'a';ch zi_map;
for(auto i = it2.first;i != it2.second;i++)
{
zi_map[i->second[1]] = i->second[0] == 1 ? ch : toupper(ch);
}
// 填入t_ret
for(auto& i: zi_map)
{
t_ret.push_back(i.second);
}
}
}
// 写入ret_ch
for(int i = ret_ch.size() -1;i>=0;i--)
{
if(ret_ch[i] != 'a')
continue;
ret_ch[i] = t_ret.back();
t_ret.pop_back();
}
// 开始打印
for(auto& i: ret_ch)
{
cout << i;
}
}
// 64 位输出请用 printf("%lld")

posted @ 2025-07-26 22:46  yjbjingcha  阅读(13)  评论(0)    收藏  举报