-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPPTRN1.cc
174 lines (163 loc) · 2.72 KB
/
SPPTRN1.cc
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define right 0;
#define down 1;
#define left 2;
#define up 3;
bool canMove(int i,int j,int dir,char* a,int size);
int move(int *i,int *j,int dir,char* a,int size);
int nextDir(int dir);
int getNextI(int i,int j,int dir);
int getNextJ(int i,int j,int dir);
bool myfn(int i, int j) { return i<j; }
int main(){
int k;
scanf("%d",&k);
int siz[k];
for(int m=0;m<k;m++){
int size;
scanf("%d",&size);
siz[m] = size;
}
int max = *max_element(siz,siz+k);
cout<<"\n";
for(int m = 0;m<k;m++){
int i = 0;
int j = 0;
int size = siz[m];
int curDir = right;
char a[size][size];
for(i = 0;i<size;i++){
for(j=0;j<size;j++){
a[i][j] = 'a';
}
}
i = 0;
j = 0;
a[i][j] = '*';
while(true){
if(canMove(i,j,curDir,(char*)a,size)){
curDir = move(&i,&j,curDir,(char*)a,size);
}
else if(canMove(i,j,nextDir(curDir),(char*)a,size)){
curDir = move(&i,&j,nextDir(curDir),(char*)a,size);
}
else{
break;
}
}
for(i = 0;i<size;i++){
for(j=0;j<size;j++){
if (a[i][j] != '*'){
a[i][j] = '.';
}
cout<<a[i][j];
}
cout<<"\n";
}
cout<<"\n";
for(i = 0;i<size;i++){
for(j=0;j<size;j++){
a[i][j] = 'a';
}
}
}
}
int move(int *i,int *j,int dir,char* a,int size){
int nextI;
int nextJ;
nextI = getNextI(*i,*j,dir);
nextJ = getNextJ(*i,*j,dir);
*i = nextI;
*j = nextJ;
*((a+*i*size)+*j) = '*';
return dir;
}
bool canMove(int i,int j,int dir, char* a,int size){
int nextI;
int nextJ;
nextI = getNextI(i,j,dir);
nextJ = getNextJ(i,j,dir);
int nextNextI;
int nextNextJ;
nextNextI = getNextI(nextI,nextJ,dir);
nextNextJ = getNextJ(nextI,nextJ,dir);
int nextDiffI;
int nextDiffJ;
nextDiffI = getNextI(nextI,nextJ,nextDir(dir));
nextDiffJ = getNextJ(nextI,nextJ,nextDir(dir));
if(nextI == size-1 && nextJ == 0){
return true;
}
if(nextJ < 0){
return false;
}
if (nextI>=size|| nextJ>=size){
return false;
}
else if(*((a+nextNextI*size)+nextNextJ) == '*'){
return false;
}
else if(*((a+nextDiffI*size)+nextDiffJ) == '*'){
return false;
}
else{
return true;
}
}
int getNextI(int i,int j,int dir){
switch(dir){
case 0:
return i;
break;
case 1:
return i+1;
break;
case 2:
return i;
break;
case 3:
return i-1;
break;
default:
return -1;
}
}
int getNextJ(int i,int j,int dir){
switch(dir){
case 0:
return j+1;
break;
case 1:
return j;
break;
case 2:
return j-1;
break;
case 3:
return j;
break;
default:
return -1;
}
}
int nextDir(int dir){
switch(dir){
case 0:
return down;
break;
case 1:
return left;
break;
case 2:
return up;
break;
case 3:
return right;
break;
default:
return dir;
}
}