import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner; public class ch1_6_7求解数字排序问题 { public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); Point a[]=new Point[n]; for(int i=0;i<n;i++) {
int k=in.nextInt();
if(hm.containsKey(k)) {
hm.put(k, hm.get(k)+1);
}
else {
hm.put(k, 1);
}
}
int s=hm.size();
int k=0;
for(java.util.Map.Entry<Integer, Integer> e:hm.entrySet()) {
a[k]=new Point();
a[k].b=e.getKey(); a[k++].c=e.getValue(); } Arrays.sort(a,0,s,new Comparator<Point>(){
public int compare(Point x,Point y){
return x.c-y.c;
} });
for(int i=s-1;i>=0;i--) {
System.out.println(a[i].b+" "+a[i].c);
}
} } class Point{ public int c;
public int b;
}

ch1_6_7求解数字排序问题的更多相关文章

  1. 【MySQL】【2】数字排序问题

    --我用的方案 SELECT * FROM TABLE_Q ORDER BY CAST(ID AS SIGNED) ASC 备注: 不做特殊处理的话,数字位数不一样时排序有问题,比如10会比2小. 其 ...

  2. 使用 线性规划 解决 数字 排序问题, +Leapms模型

    问题 将如下一组数字从大到小排序. {10, 20, -32, 177, 0, -11.5, 19, 7, 6.2, -6.28, -2.71, 44} 解决办法 建立数学模型,给出各个数字的次序值. ...

  3. easyui实现datagrid数字排序问题

    我们在使用easyui对列进行自动排序的时候(即顺序倒序),正常情况下是通过设置field中的sortable:true属性来控制是否可以排序.但是我们会发现一个有趣的问题,在对数字进行排序的时候,这 ...

  4. c#按字符串中的数字排序问题

    在.net 的framewrok框架中提供的排序方法中,如string.sort() 或ArrayList.Sort()方法.这两个方法对字符串排序时,如果字符串中含有数字,则不会按数字大小排序.如: ...

  5. DataTable 数字排序问题

    问题:DataTable 的默认排序功能是按字符来排的.在js里,把数字当字符串来排序会很大的问题,例如:"2" > "11" 返回的是 true 解决办 ...

  6. 解决oracle语句中 含数字的字符串按数字排序问题

    普通排序利用:order by 字段名 ASC 但是遇到有中文而且类型是varchar类型的结果就是这样 政采代(甲)字第0298号 政采代(甲)字第0421号 政采代(甲)字第1098号 政采代(甲 ...

  7. SpriteBuilder中关于大量CCB文件的数字命名建议

    开发者总是频繁的填充文件名字使用额外的0,以此来对抗长久以来的长痘:数字排序.如果你觉得在数字名字前添加额外的0是一个好主意,比如说Level0001,因为可能你会创建数以千记的关卡--请不要这样做! ...

  8. MYSQL字符类型数值排序

    今天遇到MySQL数字排序问题,我的排序字段是经过计算后的,而计算后的字段直接拿来排序就会按照字符一个个排序,所以这里找到简单的方法, ORDER BY 排序字段* 或者 ORDER BY 排序字段+ ...

  9. SQL 笔记 By 华仔

    -------------------------------------读书笔记------------------------------- 笔记1-徐 最常用的几种备份方法 笔记2-徐 收缩数据 ...

随机推荐

  1. PostCSS All In One

    PostCSS All In One https://postcss.org/ https://www.webpackjs.com/loaders/postcss-loader/ https://gi ...

  2. what's the print number means after called the setTimeout function in Chrome console?

    what's the print number means after called the setTimeout function in Chrome console? javascript fun ...

  3. macOS 显示/隐藏 AirPlay

    macOS 显示/隐藏 AirPlay AirPlay Sidecar 必须用相同的 Apple ID 登录 mac 和 ipad, 才能使用! https://www.apple.com/macos ...

  4. how to auto open a url in the browser by using terminal

    how to auto open a url in the browser by using terminal Linux / MacOS # bash / zsh $ open http://loc ...

  5. Taro Next

    Taro Next Taro 2.0 https://aotu.io/notes/2020/02/03/taro-next-alpha/index.html Taro Next 的迁移指南 https ...

  6. 【Python核心编程笔记】一、Python中一切皆对象

    Python中一切皆对象 本章节首先对比静态语言以及动态语言,然后介绍 python 中最底层也是面向对象最重要的几个概念-object.type和class之间的关系,以此来引出在python如何做 ...

  7. el-input输入框的readonly属性

    readonly属性是Boolean类型,默认值为false.readonly值为true表示只读. <el-col :span="12"> <el-form-i ...

  8. 2021-2-26:为什么需要 System.gc() ?

    JVM 默认启动参数中,DisableExplicitGC 为 false,ExplicitGCInvokesConcurrent 为 false,对于大多数 GC (除了 ZGC 的其他 GC,包括 ...

  9. OAuth2.0安全设计之Authorization Code

    OAuth 2.0 有 4 种认证流程: 授权码模式(authorization code) 简化模式(implicit) 密码模式(resource owner password credentia ...

  10. zabbix Python3管理

    import requests import json import os # user config here ip = '192.168.52.130' user = "root&quo ...