我正在尝试将字符串单词插入向量中,然后让它发生。我在这里做了重要的工作。问题在于计算每个字符出现次数低于代码计数的单词。
可能我将字符插入向量而不是单词。我试图从谷歌获得解决方案,但没有得到我想要的。
#include <iostream>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <unordered_map>
std::pair < int, std::string > mytransform(const std::pair < std::string, int >p)
{
return std::pair < int, std::string > (p.second, p.first);
}
int main(int argc, char *argv[])
{
std::string result_string=argv[1];
std::istringstream iss;
std::multimap < int, std::string, std::greater < int >>dst;
std::multimap < int, std::string >::iterator rec;
typedef std::unordered_map<std::string,int> occurrences;
occurrences s1;
std::vector<std::string> most;
std::map < std::string, int >src;
std::vector<std::string> writable(result_string.size() + 1);
std::copy(result_string.begin(), result_string.end(), writable.begin());
for (std::vector < std::string >::iterator it = writable.begin(); it != writable.end(); it++)
++src[*it];
std::transform(src.begin(), src.end(), std::inserter(dst, dst.begin()), mytransform);
std::multimap < int, std::string >::iterator it = dst.begin();
for (it = dst.begin(); it != dst.end(); ++it)
std::cout << it->second << ":" << it->first << std::endl;
return 0;
}
输出:
technoworld@ubuntu:~/Videos/LinSocket/Modular$ ./q "one one two"
o:3
:2
e:2
n:2
t:1
w:1
:1
而是应该是:
technoworld@ubuntu:~/Videos/LinSocket/Modular$ ./q "one one two"
one:2
two:1