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
| #include "ptoc.h"
const integer n = 30;
const integer m = 2;
array<1,n,word> mas;
matrix<1,n, 1,2,word> popular;
word f, p, i, j, k;
int main(int argc, const char* argv[])
{
pio_initialize(argc, argv);
randomize;
for( i = 1; i <= n; i ++)
{
mas[i] = random(5);
output << format(mas[i],2);
}
for( i = 1; i <= n-1; i ++)
for( j = i+1; j <= n; j ++)
if (mas[i] > mas[j])
{
k = mas[i];
mas[i] = mas[j];
mas[j] = k;
}
output << NL;
i = 1;
p = 1;
output << "Vsego" << NL;
do {
k = 1;
while ((mas[i] == mas[i+1])&&(i<n))
{
k += 1;
i += 1;
}
output << mas[i] << " - " << format((real)(k*100)/n,0,2) << '%' << NL;
popular[p][1] = k;
popular[p][2] = mas[i];
p += 1;
i += 1;
} while (!(i > n));
for( i = 1; i <= p-2; i ++)
for( j = i+1; j <= p-1; j ++)
if (popular[i][1] < popular[j][1])
for( f = 1; f <= 2; f ++)
{
k = popular[i][f];
popular[i][f] = popular[j][f];
popular[j][f] = k;
}
output << "Itogo" << NL;
if (p > m) p = m;
for( i = 1; i <= p; i ++)
output << popular[i][2] << " - " << format((real)(popular[i][1]*100)/n,0,2) << '%' << NL;
input >> NL;
return EXIT_SUCCESS;
} |