日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数据结构实验:哈希表

發布時間:2023/12/31 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据结构实验:哈希表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

數據結構實驗:哈希表

題目描述

在n個數中,找出出現次數最多那個數字,并且輸出出現的次數。如果有多個結果,輸出數字最小的那一個。

輸入

單組數據,第一行數字n(1<=n<=100000)。
接下來有n個數字,每個數字不超過100000000

輸出

出現次數最多的數字和次數。

示例輸入

3 1 1 2

示例輸出

1 2 #include<stdio.h> #include<stdlib.h> struct node {int data;int ans;struct node *next; }*head[100010]; int main() {int i, n, x, y, shu = -1, ci = -1;struct node *p, *q, *r;for(i=0; i<100000; i++) {head[i] = (struct node *)malloc(sizeof(struct node));head[i]->next = NULL;}scanf("%d", &n);for(i=0; i<n; i++) {scanf("%d", &x);y = x % 100000;p = head[y]->next;q = head[y];while(p != NULL) {if(p->data == x) {p->ans++;if(ci < p->ans) {shu = p->data;ci = p->ans;}else if(ci == p->ans) {if(shu > p->data)shu = p->data;}break;}q = p;p = p->next;}if(p == NULL) {r = (struct node *)malloc(sizeof(struct node));r->data = x;r->ans = 1;if(ci < r->ans) {shu = r->data;ci = r->ans;}else if(ci == r->ans) {if(shu > r->data)shu = r->data;}q->next = r;r->next = NULL;}}printf("%d %d\n", shu, ci);return 0; }

轉載于:https://www.cnblogs.com/Genesis2018/p/8304784.html

總結

以上是生活随笔為你收集整理的数据结构实验:哈希表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。