-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2005 S2.cpp
65 lines (45 loc) · 1.4 KB
/
2005 S2.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
/*
2005 S2 - Mouse Move
Difficulty: Very Easy
No special algorithm, you quite literaly just implement the problem and output the answer
*/
#include <iostream>
#include <utility>
int main(){
std::pair<int, int> screenDimensions;
std::cin >> screenDimensions.first >> screenDimensions.second;
std::pair<int, int> mousePos;
mousePos.first = 0;
mousePos.second = 0;
//Loop until 0, 0 is inputted
while (true){
std::pair<int, int> instruction;
std::cin >> instruction.first >> instruction.second;
//Input terminated
if (instruction.first == 0 && instruction.second == 0){
break;
}
//Apply changes to mouse position
mousePos.first += instruction.first;
mousePos.second += instruction.second;
//If too far left
if (mousePos.first < 0){
mousePos.first = 0;
}
//If too far right
else if (mousePos.first > screenDimensions.first){
mousePos.first = screenDimensions.first;
}
//If too far down
if (mousePos.second < 0){
mousePos.second = 0;
}
//If too far up
else if (mousePos.second > screenDimensions.second){
mousePos.second = screenDimensions.second;
}
//Output answer
std::cout << mousePos.first << ' ' << mousePos.second << '\n';
}
return 0;
}