forked from fatemehkarimi/uvaSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva-10920.cpp
51 lines (36 loc) · 760 Bytes
/
uva-10920.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
//uva 10920
//Spiral Tap
#include <iostream>
using namespace std;
int main(void)
{
long long int n = 0, num;
while (true) {
cin >> n >> num;
if (n == 0)
break;
long long int x = n / 2;
long long int y = n / 2;
long long int n_col = 1;
long long int n_row = 1;
bool direction = 1;//1 indicates up/down, 0 indicates left/right
int value = -1;
num -= 1;
while (num > 0) {
long long int amount = min(num, direction ? n_col : n_row);
num -= amount;
if (direction){//travel up/down
x += (amount * value);
++n_col;
}
else{
y += (amount * value);
++n_row;
value *= -1;
}
direction = !direction;
}
cout << "Line = " << n - x << ", column = " << y + 1 << "." << endl;
}
return 0;
}