-
Notifications
You must be signed in to change notification settings - Fork 5
/
UVA-512.cpp
116 lines (111 loc) · 1.94 KB
/
UVA-512.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<cstring>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
#define MAXN 55
struct Cell {
int x,y;
};
Cell arr[MAXN][MAXN];
int arr1[MAXN];
char ss[10];
int r,c,k;
void INI() {
int i,j;
for(i=1; i<=r; ++i)
for(j=1; j<=c; ++j)
arr[i][j] = (Cell) {i,j};
}
void EX() {
int x,y,xi,yi;
int x1,y1,x2,y2,i,j;
scanf("%d %d %d %d", &x, &y, &xi, &yi);
for(i=1;i<=r;++i)
for(j=1;j<=c;++j) {
if(arr[i][j].x == x && arr[i][j].y == y) {
x1 = i;
y1 = j;
}
if(arr[i][j].x == xi && arr[i][j].y == yi) {
x2 = i;
y2 = j;
}
}
swap(arr[x1][y1], arr[x2][y2]);
}
void I(int t) {
int i,j,ii;
for(ii=k-1;ii>=0;--ii) {
for(i=1;i<=r;++i) {
for(j=1;j<=c;++j) {
if(t == 1 && arr[i][j].y >= arr1[ii]) {
arr[i][j].y += 1;
continue;
}
if(t == 2 && arr[i][j].x >= arr1[ii]) {
arr[i][j].x += 1;
continue;
}
if(t == 3) {
if(arr[i][j].y == arr1[ii]) {
arr[i][j].x = 0;
arr[i][j].y = 0;
continue;
}
if(arr[i][j].y > arr1[ii])
arr[i][j].y -= 1;
continue;
}
if(t == 4) {
if(arr[i][j].x == arr1[ii]) {
arr[i][j].x = 0;
arr[i][j].y = 0;
continue;
}
if(arr[i][j].x > arr1[ii])
arr[i][j].x -= 1;
}
}
}
}
}
int main() {
int x,y,i,j,ri,ci,t,tt=0;
string s;
while(scanf("%d %d", &r, &c) == 2 && r != 0) {
printf("Spreadsheet #%d\n", ++tt);
INI();
scanf("%d", &t);
while(t--) {
scanf("%s", ss);
s = ss;
if(s == "EX") {
EX();
continue;
}
scanf("%d", &k);
for(i=0;i<k;++i)
scanf("%d", arr1+i);
sort(arr1, arr1+k);
if(s == "IC")
I(1);
if(s == "IR")
I(2);
if(s == "DC")
I(3);
if(s == "DR")
I(4);
}
scanf("%d", &t);
while(t--) {
scanf("%d %d", &x, &y);
printf("Cell data in (%d,%d) ", x, y);
if(arr[x][y].x == 0)
puts("GONE");
else
printf("moved to (%d,%d)\n", arr[x][y].x, arr[x][y].y);
}
}
return 0;
}