http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; void printarray(int arr[], int n) {
map<int, int> S;
for (int i = ; i < n; i++) {
if (S.find(arr[i]) == S.end()) S[arr[i]] = ;
else S[arr[i]]++;
}
map<int, vector<int> > T;
for (map<int, int>::iterator it = S.begin(); it != S.end(); it++) {
T[it->second].push_back(it->first);
}
for (map<int, vector<int> >::iterator it = T.end(); it != T.begin();) {
it--;
vector<int> tmp = it->second;
for (int j = ; j < tmp.size(); j++) {
for (int k = ; k < it->first; k++) cout << tmp[j] << " ";
}
}
} int main() {
int arr[] = {, , , , , , , , , , };
printarray(arr, );
return ;
}

Data Structure Array: Sort elements by frequency的更多相关文章

  1. Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times

    http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-tha ...

  2. Data Structure Array: Maximum sum such that no two elements are adjacent

    http://www.geeksforgeeks.org/maximum-sum-such-that-no-two-elements-are-adjacent/ #include <iostre ...

  3. Data Structure Array: Find the Missing Number

    http://www.geeksforgeeks.org/find-the-missing-number/ 1. use sum formula, O(n), O(1) 2. use XOR, O(n ...

  4. Data Structure Array: Move all zeroes to end of array

    http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...

  5. Data Structure Array: Find if there is a subarray with 0 sum

    http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ #include <iostream> #incl ...

  6. Data Structure Array: Maximum circular subarray sum

    http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...

  7. Data Structure Array: Largest subarray with equal number of 0s and 1s

    http://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s/ #include <iostream& ...

  8. Data Structure Array: Find the two numbers with odd occurrences in an unsorted array

    http://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/ #include ...

  9. Data Structure Array: Longest Monotonically Increasing Subsequence Size

    http://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/ #include < ...

随机推荐

  1. Android网络框架Volley

    Volley是Google I/O 2013推出的网络通信库,在volley推出之前我们一般会选择比较成熟的第三方网络通信库,如: android-async-http retrofit okhttp ...

  2. PHP接收和发送XML数据(json也通用)

    一.接收xml数据, 使用php://input,代码如下: <?php $xmldata=file_get_contents("php://input"); $data=s ...

  3. java.long中的类和方法

    java.lang.Character.isUpperCase(char ch) 确定指定的字符是否为大写字符. java.lang.Character.toUpperCase()方法用法转换从Uni ...

  4. Google 商店

    Google 商店地址:https://store.google.com/

  5. SpringMvc入门教程

    1.新建demo4  web项目, 导入spring包(使用的是spring4.2) 2.修改WEB-INF下的WEB.XML内容为 <?xml version="1.0" ...

  6. Error in as.POSIXlt.character(x, tz, ...) :

    > sqlFetch(channel,"user")Error in as.POSIXlt.character(x, tz, ...) :   character strin ...

  7. 爬虫的原理获取html中的图片到本地

    如果你想获取哪个网页的图片,如果你想知道那个网址的美女,还等什么.代码走起:下载即可使用 完成这次瞎爬的原理如下: 第一步:获取html内容 * 第二步:然后在获取的html文本中寻找图片,根据htm ...

  8. 在Linux下搭建Git服务器步骤

    环境: 服务器 CentOS6.6 + git(version 1.7.1) 客户端 Windows10 + git(version 2.8.4.windows.1)  ① 安装 Git Linux ...

  9. git使用命令行方式提交代码到github或gitlab上

    (1)使用命令行(Git Bash)在gitlab上新建项目的流程   //进入项目目录下: C:\Users\wuwy>cd D:\workspace\eclipse\H5Patient\// ...

  10. 请求SQL数据是存在<null>,的解决方法

    删除字典中的null 我们在处理服务器传过来的数据过程中,如果数据中出现null,我们是没法进行本地持久化处理的.在使用NSUserDaults保存本地时,如果其中一个字段的value为NULL值,就 ...