-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path464_Pelotón.cpp
84 lines (76 loc) · 1.97 KB
/
464_Pelotón.cpp
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
// Usuario de Acepta el reto: jjjjjjjp022
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
int main()
{
int n;
cin >> n;
while (cin)
{
char aux;
struct tHora {
int segundos, position, clasif;
};
vector <tHora> time(n, { 0, -1 , 0});
int tmp;
for (int i = 0; i < n; i++)
{
cin >> tmp;
time[i].segundos += tmp * 60 * 60;
cin.get(aux);
cin >> tmp;
time[i].segundos += tmp * 60;
cin.get(aux);
cin >> tmp;
time[i].segundos += tmp;
time[i].position = i;
}
//Ordenar por segundos (menor a mayor) (método de la burbuja)
bool ordenado = false;
while (!ordenado)
{
ordenado = true;
for (int i = 1; i < n; i++)
{
if (time[i - 1].segundos > time[i].segundos)
{
ordenado = false;
swap(time[i - 1], time[i]);
}
}
}
//Asignar clasificación
time[0].clasif = 1;
for (int i = 1; i < n; i++)
{
if (time[i].segundos <= time[i - 1].segundos + 1)
time[i].clasif = time[i - 1].clasif;
else
time[i].clasif = i + 1;
}
//Ordenar por position (método de la burbuja)
ordenado = false;
while (!ordenado)
{
ordenado = true;
for (int i = 1; i < n; i++)
{
if (time[i - 1].position > time[i].position)
{
ordenado = false;
swap(time[i - 1], time[i]);
}
}
}
for (int i = 0; i < n; i++)
{
cout << time[i].clasif << endl;
}
cout << "---" << endl;
cin >> n;
}
}