0% found this document useful (0 votes)
19 views

Codtest

some code

Uploaded by

Tuti Zboara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Codtest

some code

Uploaded by

Tuti Zboara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <fstream>

#include <iostream>

using namespace std;

ifstream f("in.txt");
ofstream g("out.txt");

int main()
{
int n;

f >> n;
for (int i = 0; i < n; i++) {
int x, y, z;
int a[501][501] = { 0 };
f >> x >> y >> z;
int k;
int id = 1;

for (int j = 1; j <= y; j+=2) {


for (k = 1; k <= x/3*3; k+=3) {
a[j][k] = id;
a[j][k+1] = id;
}
}
if (x - x / 3 * 3 == 2) {
for (int j = 1; j <= y; j += 2) {
a[j][k] = id;
a[j][k+1] = id;
}
}
else{
for (int j = 1; j <= y / 3 * 3; j += 3) {
a[j][k] = id;
a[j+1][k] = id;
}
if (y - y / 3 * 3 == 2 && x % 3 >= 1) {
a[y][x] = id;
a[y-1][x] = id;
}
}

for (int i = 1; i <= y; i++) {


for (int j = 1; j <= x; j++) {
if (a[i][j]) {
g << 'X';
}
else
g << '.';
}
g << "\n";
}
g << "\n";
}
}
--------------------

#include <fstream>
#include <iostream>

using namespace std;

ifstream f("in.txt");
ofstream g("out.txt");

int main() {

int a[101][101] = { 0 };

int n, m, z;
f >> n >> m >> z;
int top = 1, bottom = n, left = 1, right = m;

while (top <= bottom && left <= right) {


int k = top;
int i = 1;
bool ok = false;
while (i <= right) {

a[k][i] = 1;
a[k+1][i] = 1;
if (i == right - 3) {
a[top][right] = 1;
a[top][right - 1] = 1;
top += 2;
ok = true;
break;
}
i+=2;
}
if (ok != true) {
top += 3;
}

k = right;
i = top;
ok = false;
while (i <= bottom) {
a[i][k] = 1;
a[i][k-1] = 1;
if (i == bottom - 3) {
a[right][bottom] = 1;
a[right][bottom-1] = 1;
right -= 2;
ok = true;
break;
}
i += 2;
}
if (ok != true) {
right -= 3;
}

k = bottom;
i = right;
ok = false;
while (i >= left ) {
a[k][i] = 1;
a[k-1][i] = 1;
if (i == left + 3) {
a[left][bottom] = 1;
a[left][bottom+1] = 1;
bottom -= 2;
ok = true;
break;
}
i += 2;
}
if (ok != true) {
bottom -= 3;
}
k = left;
i = bottom;
ok = false;
while (i >= top) {
a[i][k] = 1;
a[i][k+1] = 1;
if (i == top + 3) {
a[top][left] = 1;
a[top][left + 1] = 1;
left += 2;
ok = true;
break;
}
i += 2;
}
if (ok != true) {
left += 3;
}

}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
g << a[i][j] << " ";
}
g << "\n";
}

return 0;
}

You might also like