C# Programming Basics Online Exam - 14 and 15 April 2018 - PIN
Здравейте!
Моля за съдействие. Решавам тук една задача - https://judge.softuni.bg/Contests/Practice/Index/978#13 .
Zero тестовете ми са ок. А всички останали се провалят.
Гледах, гледах. Не мога да открия, къде е евентуално грешката.
Прилагам и сорса. При мен се компилира ок. И изглежда ок. Измерил съм и колоните и редовете. Верни са.
Поздрави и благодаря предварително!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class DrawTheWordPin
{
static void Main(string[] args)
{
int userInput = int.Parse(Console.ReadLine());
int imageWidth = 6 * userInput + 10;
if (userInput >= 2 &&
userInput <=20)
{
DrawTopLine(userInput, imageWidth);
DrawUpperLines(userInput, imageWidth);
DrawMiddleLine(userInput, imageWidth);
DrawLowerLines(userInput, imageWidth);
DrawBottomLine(userInput, imageWidth);
}
else
{
Console.WriteLine("Enter correct number between 2 and 20");
}
}
private static void DrawTopLine(int userInput, int imageWidth)
{
Console.Write("/`");
for (int i = 0; i < userInput * 2; i++)
{
Console.Write("P");
}
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("/`I");
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("/`N");
for (int i = 0; i <= userInput * 2; i++)
{
Console.Write(" ");
}
Console.Write("N\n");
}
private static void DrawUpperLines(int userInput, int imageWidth)
{
for (int a = 0; a < userInput - 1; a++)
{
Console.Write("| P");
for (int b = 0; b < userInput * 2 - 2; b++)
{
Console.Write(" ");
}
Console.Write("P");
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("| I");
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("| N");
for (int i = 0; i < a; i++)
{
Console.Write(" ");
}
Console.Write("N");
for (int i = 0; i <= userInput * 2 - 1 - a; i++)
{
Console.Write(" ");
}
Console.Write("N\n");
}
}
private static void DrawMiddleLine(int userInput, int imageWidth)
{
Console.Write("| ");
for (int i = 0; i < userInput * 2; i++)
{
Console.Write("P");
}
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("| I");
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("| N");
for (int i = 0; i < userInput - 1; i++)
{
Console.Write(" ");
}
Console.Write("N");
for (int i = 0; i <= userInput * 2 - userInput; i++)
{
Console.Write(" ");
}
Console.Write("N\n");
}
private static void DrawLowerLines(int userInput, int imageWidth)
{
for (int a = 0; a < userInput; a++)
{
Console.Write("| P");
if (userInput > 2)
{
Console.Write("P");
}
else
{
Console.Write(" ");
}
for (int b = 0; b < userInput * 2 - 2; b++)
{
Console.Write(" ");
}
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("| I");
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("| N");
for (int i = 0; i < userInput + a; i++)
{
Console.Write(" ");
}
Console.Write("N");
for (int i = 0; i < userInput * 2 - userInput - a; i++)
{
Console.Write(" ");
}
Console.Write("N\n");
}
}
private static void DrawBottomLine(int userInput, int imageWidth)
{
Console.Write("\\_P");
if (userInput > 2)
{
Console.Write("P");
}
else
{
Console.Write(" ");
}
for (int b = 0; b < userInput * 2 - 2; b++)
{
Console.Write(" ");
}
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("\\_I");
for (int i = 0; i < userInput; i++)
{
Console.Write(" ");
}
Console.Write("\\_N");
for (int i = 0; i <= userInput; i++)
{
Console.Write(" ");
}
Console.Write(" ");
for (int i = 0; i < userInput * 2 - userInput - 2; i++)
{
Console.Write(" ");
}
Console.Write("NN\n");
}
}
Брат!
Ти си извънземен!
Със стринговете е супер, но аз просто не мога да ти разчета кода!
Благодаря за съпорта все пак. Доста е умен!
Събрано всичко в 20 реда е мега яко!
Поздрави!
Би ли ми разкрил малко от логиката на това, което си направил.
Или по-скоро, можем ли да не задълбаваме задачите на много редове. Познавайки C#.
Благодаря ти!
Тези задачи с рисуването се решават с new string. Намерих тема във форума, където колега го е обяснил. https://softuni.bg/forum/9477/string-vs-new-string На лекции трябва да са ви го обеснявали също.
е то няма нищо извънземно в кода,човека ползва override на tostring и презаписването с new другото е просто нагаждане на нещата. Да ефектно е че е кратко така но не е някаква извънземна наука. То това му е силатан а с# пред java примерно че прави такива магий,те затова и всички се радват на js python при тях става още по брутално.Не е ясно на лекциите защо не са ви го показали поне това с new string. Общо взето ти си hardcode-всички неща а колегата ги е направил функционално.