复盘笔试题
对输入字符串里的单词进行排序:
1.根据单词出现的次数进行降序排序。
2.相同次数的单词根据单词长度进行升序排序。
3.每个单词根据字典顺序进行排序。
示例:
输入:hello world in is on is
输出:is is in no ehllo dlorw
代码展示:菜鸟办法
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
string str;
while (getline(cin, str))
{
stringstream ss(str);
string s;
vector<string>words; // 存放单词
while (getline(ss, s, ' '))
{
words.push_back(s);
}
// 统计的单词出现频次
map<string, int> mp