-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBestTime2Party.c
77 lines (61 loc) · 1.83 KB
/
BestTime2Party.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
#include <stdlib.h>
#include <stdio.h>
#define ARRSIZE(arr) (sizeof(arr)/sizeof(*(arr)))
int compare(const void* a, const void* b) {
int x1 = *(int*)a;
int x2 = *(int*)b;
if (x1 > x2) return 1;
if (x1 < x2) return -1;
int y1 = *(((int*)a)+1);
int y2 = *(((int*)b)+1);
if (y1 > y2) return 1;
if (y1 < y2) return -1;
return 0;
}
int main()
{
int metal_num;
printf("Dwse arithmo apo metal bands:");
scanf("%d", &metal_num);
int i,j;
int matrix[metal_num*2][2];
for(i=0;i<metal_num;i++){
printf("Stigmi afiksis metal band %d:",i+1);
scanf("%d", &matrix[i][0]);
matrix[i][1]=1;
printf("Stigmi apoxwrisis metal band %d:",i+1);
scanf("%d", &matrix[i+metal_num][0]);
matrix[i+metal_num][1]= -1;
}
int k,l,t,t1;
for(k=0;k<metal_num-1;k++){
for(i=0;i<metal_num-k-1;i++){
if(matrix[i][0]<matrix[i+1][0]){
t = matrix[i][0];
matrix[i][0] = matrix[i+1][0];
matrix[i+1][0] = t;
}
else if(matrix[i][0]==matrix[i+1][0]){
if(matrix[i][1]<matrix[i+1][1]){
t1 = matrix[i][1];
matrix[i][1] = matrix[i+1][1];
matrix[i+1][1] = t1;
}
}
}
}
int metals = 0;
int maxcount = 0;
int ora = 0;
qsort(matrix, ARRSIZE(matrix), sizeof(*matrix), compare);
for (i = 0; i < metal_num*2; i++){
metals = metals + matrix[i][1];
if (metals > maxcount){
maxcount = metals;
ora = matrix[i][0];
}
}
printf("Ora pou prepei na paei : %d\n", ora);
printf("Opou tha einai ekei :%d metal bands",maxcount);
return 0;
}