+ Нов въпрос

## Sheriff

Здравейте,

Някой има ли решението на тази задача?

https://judge.softuni.bg/Contests/Practice/Index/784#4

Благодаря предварително.

Тагове:
0
Todor030366 8 Точки

имам я на java:

import java.util.Scanner;

public class Sheriff {

static String repeatStr(String strToRepeat, int count) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++) {
sb.append(strToRepeat);
}
return sb.toString();
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());

String firstLine = repeatStr(".", (n * 3 - 1) / 2) + "x" + repeatStr(".", (n * 3 - 1) / 2);
System.out.println(firstLine);
String secondLine = repeatStr(".", (n * 3 - 3) / 2) + "/x\\" + repeatStr(".", (n * 3 - 3) / 2);
System.out.println(secondLine);
String tirthLine = repeatStr(".", (n * 3 - 3) / 2) + "x|x" + repeatStr(".", (n * 3 - 3) / 2);
System.out.println(tirthLine);
for (int i = 0; i < (n - 1) / 2; i++) {
String cycle = repeatStr(".", (n * 3 - 1) / 2 - n - i) + repeatStr("x", n + i)
+ "|"
+ repeatStr("x", n + i)
+ repeatStr(".", (n * 3 - 1) / 2 - n - i);
System.out.println(cycle);
}
String middle = repeatStr("x", (n*3-1)/2) + "|" + repeatStr("x", (n*3-1)/2);
System.out.println(middle);

for (int i = 0; i < (n - 1) / 2 ; i++) {
String cycleReverse = repeatStr(".", 1 + i) + repeatStr("x", (n*3 - 3)/2 - i)
+ "|"
+ repeatStr("x", (n*3 - 3)/2 - i)
+ repeatStr(".", 1 + i);
System.out.println(cycleReverse);
}
System.out.println(secondLine);
String secondLineMirrored = repeatStr(".", (n * 3 - 3) / 2) + "\\x/" + repeatStr(".", (n * 3 - 3) / 2);
System.out.println(secondLineMirrored);
for (int i = 0; i < (n - 1) / 2; i++) {
String cycle = repeatStr(".", (n * 3 - 1) / 2 - n - i) + repeatStr("x", n + i)
+ "|"
+ repeatStr("x", n + i)
+ repeatStr(".", (n * 3 - 1) / 2 - n - i);
System.out.println(cycle);
}

System.out.println(middle);

for (int i = 0; i < (n - 1) / 2 ; i++) {
String cycleReverse = repeatStr(".", 1 + i) + repeatStr("x", (n*3 - 3)/2 - i)
+ "|"
+ repeatStr("x", (n*3 - 3)/2 - i)
+ repeatStr(".", 1 + i);
System.out.println(cycleReverse);
}
System.out.println(tirthLine);
System.out.println(secondLineMirrored);
System.out.println(firstLine);
}
}

0

Благодаря! Малко ще ми е трудно да го преработя на c#.

0

Много благодаря!

0
j0nze 39 Точки
0
Cherkezova 4 Точки

Ето още едно решение:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sheriff
{
class Program
{
static void Main(string[] args)
{

int collumn = 3 * n;

while (n % 2 == 0)
{
Console.WriteLine("Само нечетни");
}

//FIRST THREE ROWS
Console.WriteLine("{0}x{0}", new string('.', collumn / 2));

Console.WriteLine("{0}/x\\{0}", new string('.', collumn / 2 - 1));

Console.WriteLine("{0}x|x{0}", new string('.', collumn / 2 - 1));

// First Part of MIDDLE 1

for (int i = 0; i < (n - 1)/2; i++)
{
Console.WriteLine("{0}{1}|{1}{0}", new string('.', (collumn - 1)/ 2 - n - i), new string('x', n + i));

}
Console.WriteLine("{0}|{0}", new string('x', collumn / 2));

// Secon Part of MIDDLE 1

for (int i = 0; i < (n - 1)/ 2; i++)
{
Console.WriteLine("{0}{1}|{1}{0}", new string('.', 1 + i), new string('x', (collumn - 3 )/ 2 - i));
}

// FOOTER

Console.WriteLine("{0}/x\\{0}", new string('.', collumn / 2 - 1));

Console.WriteLine("{0}\\x/{0}", new string('.', collumn / 2 - 1));

// First Part of MIDDLE 2

for (int i = 0; i < (n - 1) / 2; i++)
{
Console.WriteLine("{0}{1}|{1}{0}", new string('.', (collumn - 1) / 2 - n - i), new string('x', n + i));

}
Console.WriteLine("{0}|{0}", new string('x', collumn / 2));

// Secon Part of MIDDLE 2

for (int i = 0; i < (n - 1) / 2; i++)
{
Console.WriteLine("{0}{1}|{1}{0}", new string('.', 1 + i), new string('x', (collumn - 3) / 2 - i));
}

//Last three rows

Console.WriteLine("{0}x|x{0}", new string('.', collumn / 2 - 1));

Console.WriteLine("{0}\\x/{0}", new string('.', collumn / 2 - 1));

Console.WriteLine("{0}x{0}", new string('.', collumn / 2));

}

}
}

0