请问这个问题怎么实现,C语言

来源:百度知道 编辑:UC知道 时间:2024/05/22 08:21:19
【问题描述】
输入若干个整数,统计出现次数最多的那个整数。如果出现最多的整数有两个以上,打印最早输入的那个整数。
【输入形式】
从标准输入读取输入。第一行只有一个数字N(1≤N≤10000),代表整数的个数。以后的N行每行有一个整数。
【输出形式】
向标准输出打印出现次数最多的那个数字。
【输入样例】
6
11
0
-1
20
0
300
【输出样例】
0

【样例说明】
输入6个整数,其中出现次数最多的是0,共出现两次。

不可以使用数学库函数

#include<stdio.h>
struct num
{
int n;
int count;

};

struct num nn[100];

main()
{

int *a,*b;
int n,i,t;

while(t=scanf("%d\n",&n),t!=-1)
{
功能是输入数字,如果发现有重复的数字,让n对应的.count的值加1
*a++=t;
}

{

这部分为判断.count里哪个数最大,并输出其对应的n值
}

}

请帮忙,谢谢!
程序正确回报50分

#include <stdio.h>
#include <stdlib.h>

typedef struct tag_num
{
int data;
int count;
struct tag_num *next;
}NUM;

/* insert number and count it */
void put_number( NUM *head, int num );

/* get number which have max count */
int get_max_num( NUM *head );

/* init link */
NUM* init_link();

/* destroy link */
void destroy_link( NUM *head );

int main( int argc, char *argv[] )
{
int i, num = 0, n = 0;
NUM *head = 0;

/* init link */
head = init_link();

/* read N */
printf( "Input N: " );
scanf( "%d", &n );

/* read enough number*/
printf( "Now, input %d number:\n", n );
for ( i = 0; i < n; i++ )
{
scanf( "%d", &num );
put_number( head, num ); /* insert and count */
}

num = get_max_num( head );