forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
/
acs.cpp
53 lines (53 loc) · 765 Bytes
/
acs.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
// 2008-06-20
#include <iostream>
using namespace std;
int main()
{
int x[5678];
int X[5678];
int y[1234];
int Y[1234];
int _x,_y,z,a,b,i;
char c;
for (i=0; i<1234; i++)
{
y[i]=i;
Y[i]=i;
}
for (i=0; i<5678; i++)
{
x[i]=i;
X[i]=i;
}
while (!cin.eof())
{
c=getchar();
if (c=='C')
{
scanf("%d %d",&a,&b);
swap(X[x[a-1]],X[x[b-1]]);
swap(x[a-1],x[b-1]);
}
else if (c=='R')
{
scanf("%d %d",&a,&b);
swap(Y[y[a-1]],Y[y[b-1]]);
swap(y[a-1],y[b-1]);
}
else if (c=='Q')
{
scanf("%d %d",&a,&b);
printf("%d\n",5678*y[a-1]+x[b-1]+1);
}
else if (c=='W')
{
scanf("%d",&z);
_x=(z-1)%5678;
_y=(z-1)/5678;
printf("%d %d\n",Y[_y]+1,X[_x]+1);
}
else if (c!=' '&&c!='\n')
break;
}
return 0;
}