SDUTOJ 1480 -- 哈希表(链地址法)
来源:互联网 发布:新还珠格格第三部知画 编辑:程序博客网 时间:2024/06/01 08:49
题目描述
在n个数中,找出出现次数最多那个数字,并且输出出现的次数。如果有多个结果,输出数字最小的那一个。
输入
单组数据,第一行数字n(1<=n<=100000)。
接下来有n个数字,每个数字不超过100000000
接下来有n个数字,每个数字不超过100000000
输出
出现次数最多的数字和次数。
示例输入
31 1 2
示例输出
1 2
#include <stdio.h>#include <string.h>#include <stdlib.h>const int MAX = 100000;struct node{ int num; int time; node *next;}st[100050];int main(){ int n,i; memset(st,0,sizeof(st)); node *p,*tp; scanf("%d",&n); while(n--) { long long shu; int tmp; scanf("%lld",&shu); tmp=shu%MAX; p=&st[tmp]; tp=p; while(p!=NULL) { if(p->num==shu) { p->time++; break; } tp=p; p=p->next; } if(p==NULL) { p=new node; p->num=shu; p->time=1; p->next=NULL; tp->next=p; } } int a_num; int a_time=0; for(i=0;i<MAX;i++) { p=st[i].next; while(p!=NULL) { if(a_time<p->time) { a_time=p->time; a_num=p->num; } else if(a_time==p->time) { a_num=a_num<p->num?a_num:p->num; } p=p->next; } } printf("%d %d\n",a_num,a_time); return 0;}
0 0
- SDUTOJ 1480 -- 哈希表(链地址法)
- SDUTOJ 1480 数据结构实验:哈希表——链地址法处理冲突
- [1480]数据结构实验:哈希表 sdutOJ
- sdutoj
- SDUTOJ
- SDUToj
- SDUToj
- SDUToj
- SDUTOJ 2504 双向链表
- SDUTOJ 2054 双向链表
- 【1500】Message Flood (SDUTOJ)
- 哈希表(链地址法)
- SDUTOJ 1197 约瑟夫问题——循环链表解法数学解法和循环队列
- SDUTOJ 2057 金牌、银牌、铜牌 ——链表的插入排序法
- SDUTOJ 2118 链表的逆置
- SDUTOJ 2543 整除(容斥原理)
- sdutoj 1101 Bridge Hands (桥牌)
- SDUTOJ 1466 双向队列(队列)
- 理解PHP内核
- 图的遍历
- mount过程分析之一(基于3.16.3内核)
- MFC DLL导出类
- 视频开发之外部音视频输入
- SDUTOJ 1480 -- 哈希表(链地址法)
- 最长递增子序列
- getHeight/getTop
- 转移线程的所有权
- hive使用python脚本导致java.io.IOException: Broken pipe异常退出
- 关于Visual Studio 2013 编译 multi-byte character set MFC程序出现 MSB8031 错误的解决办法
- 用ctags为linux系统头文件生成systags
- 渍拽滋转桌妆妆撞阻祝啄孜妆拽钻组纂卒
- 查询oracle中所有用户信息