Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Todor030366 avatar Todor030366 11 Точки

имам я на 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
denitsadudinska avatar denitsadudinska 0 Точки

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

 

0
denitsadudinska avatar denitsadudinska 0 Точки

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

0
Cherkezova avatar Cherkezova 4 Точки

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

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

namespace Sheriff
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int collumn = 3 * n;
           


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

            
            //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
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.