-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path573_snail.cpp
99 lines (81 loc) · 1.7 KB
/
573_snail.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <vector>
#include <list>
#include <stdlib.h>
using namespace std;
class Caracol
{
public:
float H=1;
float U;
float D;
float F;
};
int main()
{
list<Caracol> Lista;
list<Caracol>::iterator it= Lista.begin();
(*it).H=1;
while((*it).H!=0)
{
Caracol objeto;
cin>>objeto.H;
cin>>objeto.U;
cin>>objeto.D;
cin>>objeto.F;
Lista.push_back(objeto);
it++;
}
Lista.erase(it); // Borra la línea que marca el final
it= Lista.begin();
vector<int> n_days;
vector<bool> success;
while(it!=Lista.end())
{
float height= (*it).H;
float climb= (*it).U;
float fall= (*it).D;
float fatigue= (*it).F / 100;
int cont=0;
float increment;
int i;
float pos=0;
while(1)
{
increment= climb-(cont*fatigue)*climb;
if(increment>0)
pos+= increment;
cont++; // Antes de que caiga la noche
if(pos>height)
{
success.push_back(1);
break;
}
pos-= fall;
if(pos<0)
{
success.push_back(0);
break;
}
}
n_days.push_back(cont);
it++;
}
it= Lista.begin();
int j=0;
while(it!=Lista.end())
{
//int i=distance(Lista.begin(), it);
if(success[j])
{
cout<<"success on day "<<n_days[j]<<endl;;
}
else
{
cout<<"failure on day "<<n_days[j]<<endl;
}
j++;
it++;
}
return 0;
}