输入一棵树;输出这棵树中度最大的节点编号和它的度。如果有多个节点,则输出编号最小的一个。

来源:百度知道 编辑:UC知道 时间:2024/05/20 16:12:35
输入:
7
0 2
5 4
6 3
5 1
6 5
0 6
输出:
0

#include <stdio.h>

#define max 1000

int n;

int arr[max];

void proc()
{
int i;
int x,y;
int m=0,pos=n;
for(i=0;i<n;i++) arr[i]=0;
while(scanf("%d %d",&x,&y)!=EOF)
{
arr[x]++;
if(arr[x]>m&&x<pos) pos=x;
}
printf("%d\n",pos);
}

int main()
{
scanf("%d",&n);
proc();
getch();
return 0;
}

/* huffman.c - 求赫夫曼编码。*/
#include<string.h>
#include<ctype.h>
#include<malloc.h> /* malloc()等 */
#include<limits.h> /* INT_MAX等 */
#include<stdio.h> /* EOF(=^Z或F6),NULL */
#include<stdlib.h> /* atoi() */
#include<io.h> /* eof() */
#include<math.h> /* floor(),ceil(),abs() */
#include<process.h> /* exit() */

/* 函数结果状态代码 */
#define TRUE 1
#define FALSE 0
#define OK 1