-
Notifications
You must be signed in to change notification settings - Fork 3
/
Number Appearance.c
92 lines (77 loc) · 2.24 KB
/
Number Appearance.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <stdbool.h>
int arr[1000000],count[1000000],extra[10000];
int main ()
{
int n,i,max,pos=1,p,j,cnt,l;
while (scanf ("%d",&n) != EOF && n)
{
memset (count,0,sizeof(count));
for (i=0; i<n; i++)
{
scanf ("%d",&arr[i]);
++count[arr[i]];
}
printf ("Case %d: ",pos++);
if (n == 1)
printf ("%d has appeared 1 time.\n",arr[0]);
else
{
max = count[0],p = 0;
for (i=1; i<1000000; i++)
{
if (count[i] > max)
{
max = count[i];
p = i;
}
}
bool k = false,m = false;
for (i=0; i<100000; i++)
{
if (count[i] > 1)
{
k = true;
break;
}
}
j = cnt = 0;
for (i=0; i<1000000; i++)
{
if (max == count[i])
{
cnt++;
extra[j++] = i;
}
if (cnt > 1)
m = true;
}
if (k == false)
printf ("Same appearance.\n");
else
{
if (m == false)
printf ("%d has appeared %d times.\n",p,max);
else
{
if (cnt == 2)
printf ("%d and %d have appeared %d times each.\n",extra[0],extra[1],max);
else
{
for (l=0; l<cnt; l++)
{
if (l == cnt-1)
printf ("and %d",extra[l]);
else if (l == cnt-2)
printf ("%d ",extra[l]);
else
printf ("%d, ",extra[l]);
}
printf (" have appeared %d times each.\n",max);
}
}
}
}
}
return 0;
}