我正在尝试按降序对地图进行排序,但没有得到预期的结果?
I am trying to sort the map in decreasing order but i am not getting the desired result?
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef long long int ll;
int main()
{
string s;
cin >> s;
map<char, int,greater <int>> m;
m['A'] = 1;
m['C'] = 1;
m['G'] = 1;
m['T'] = 1;
for(ll i = 0; i < s.length()-1; i++)
{
if(s[i] == s[i+1]) //ATTCGGGA
m[s[i]]++;
}
for(auto it = m.begin(); it != m.end(); it++)
{
cout <<it->first <<" " <<it->second<<endl;
}
//cout <<it->second<<endl;
return 0;
}
我想要的输出应该是 G 3 美国 一 1 C 1 但它的显示 美国 G 3 C 1 一 1 我不知道为什么会发生这种情况,因为我已经提到它在有序地图中更大。 请解决该问题?
你可以简单地使用队列。 如果要使用地图来执行此操作,请使用 multi_map((;并使用 int 作为键,使用 char 作为值,这样您就可以根据 int 值对它们进行排序
相关文章:
- 我正在尝试按降序对地图进行排序,但没有得到预期的结果?
- 读取一组用户输入,按升序排序,然后打印结果
- 计数排序给出错误的结果
- 选择排序算法生成无序结果
- 如果我将索引变量更改为零,并且合并函数中的k = 0,则获得合并排序的错误结果
- 根据标准对结构向量进行排序,然后显示结果
- 按奇偶校验对数组进行排序 结果并不可靠
- 对 3 个数字进行排序会产生奇怪的结果 (C++)
- 排序向量不断修改数据并打印不正确的结果
- 使用 c++ 中对象中的函数的结果对对象数组进行排序
- 执行“提升几何图形”最近的查询始终首先按最小距离排序结果
- std::具有自定义比较函数结果的排序函数错误:必须调用对非静态成员函数的引用
- 排序算法给出错误的结果
- 气泡排序程序未输出结果
- 关于C++11内存模型的奇怪结果(放松排序)
- 2D 矢量排序不需要的结果
- 将filter应用于Ldap搜索也会对结果进行排序
- 对输入'age'名称进行排序,然后显示结果
- C++ 集合有序迭代 - 是迭代集合的结果,按标准排序
- 线程合并排序给出无效结果