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. charles用法详解

    Charles是目前最强大的http调试工具,在界面和功能上远强于Fiddler,同时是全平台支持,堪称圣杯级工具,唯一的缺陷是这货是收费的,而且是要¥50美元大洋…当然网上是有破解版的,鄙视下自己, ...

  2. Bmob实现android云端存储

    代码地址如下:http://www.demodashi.com/demo/12547.html 前言 一直很困惑,android到底能不能将本地数据传到一个公共的云端,让云端实现数据库功能,这样的话, ...

  3. nightwatchJS ---element用法

    .element() Search for an element on the page, starting from the document root. The located element w ...

  4. cocos2dx3.0戳青蛙游戏(打地鼠)

    1戳青蛙项目描写叙述 1.1功能描写叙述 实现类似打地鼠游戏.青蛙随机出如今屏幕左边5*3的格子中,并会向屏幕右边移动,在青蛙逃离之前,手指点击实现戳灭青蛙的效果.随着分数添加,青蛙越来越多,当青蛙逃 ...

  5. OpenLayers加载天地图

    openlayer 是基于JavaScript的webGIS库 ,通过openlayer可以很容易的调用地图,并做相应的操作. 在head中载入openlayer的js文件: <link rel ...

  6. (2) yum源配置-163

    1.获取yum源文件 登录http://mirrors.163.com/.help/centos.html,查看CentOS6的链接地址(右键点击“CentOS6”,选择复制链接地址),链接地址为:h ...

  7. mysql单表导入数据,全量备份导入单表

    (1)“导出”表 导出表是在备份的prepare阶段进行的,因此,一旦完全备份完成,就可以在prepare过程中通过--export选项将某表导出了: innobackupex --apply-log ...

  8. hihoCoder #1321 : 搜索五•数独 (Dancing Links ,精确覆盖)

    hiho一下第102周的题目. 原题地址:http://hihocoder.com/problemset/problem/1321 题意:输入一个9*9数独矩阵,0表示没填的空位,输出这个数独的答案. ...

  9. iOS --创建文件夹 ,删除文件夹

    //创建文件夹 --> 返回 文件夹 - (NSString *)pathToPatientPhotoFolder { NSString *documentsDirectory = [NSSea ...

  10. React Native安装步骤

    先贴出中文网安装指南:http://reactnative.cn/docs/0.46/getting-started.html 本文会点出一些安装时遇到的坑,和解决方案! 1.首先是安装Chocola ...