-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10071.cpp
52 lines (50 loc) · 1011 Bytes
/
P10071.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
#include <iostream>
#include <ctype.h>
bool readInts(int &a, int &b) {
a = b = 0;
bool aStarted = false;
bool aDone = false;
bool negA = false;
char w[20];
if(!std::cin.getline(w, 20))
return false;
for(int i = 0; i < 20; ++i) {
if(w[i] == '-') {
if(!aStarted) {
aStarted = true;
negA = true;
}
}
else if(w[i] >= '0' && w[i] <= '9') {
if(aDone)
b = b*10 + (w[i]-'0');
else {
a = a*10 + (w[i]-'0');
aStarted = true;
}
}
else {
if(!isprint(w[i]))
break;
if(aStarted)
aDone = true;
}
}
if(negA)
a = -a;
//std::cerr << "Read " << a << ", " << b << std::endl;
return true;
}
/*
Velocity after time t: v
Displacement after time t: x0 = ½at^2, since v=at => a=v/t => x0 = ½v/t*t^2 = ½vt
Velocity after time 2t: 2v
Displacement after time 2t: ½a(2t)^2 = ½v/t(2t)^2 = ½v/t*4*t*t = 2vt
*/
int main() {
int v, t;
while(readInts(v, t)) {
std::cout << (v * 2 * t) << std::endl;
}
return 0;
}