Untitled
unknown
plain_text
5 years ago
1.2 kB
7
Indexable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
var test = Metoda2("wiersz wejsciowy");
foreach (var item in test)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
public static string[] Metoda2(string s)
{
string[] result = new string[s.Length];
int middle = s.Length / 2;
for (int i = 0; i < s.Length; i++)
{
var stringToAdd = "";
for (int j = 0; j < s.Length; j++)
{
stringToAdd += " ";
}
string currentSubstring = s.Substring(0, i + 1);
stringToAdd = stringToAdd.Substring(0, middle - currentSubstring.Length / 2) + currentSubstring + stringToAdd.Substring(middle + currentSubstring.Length/2);
result[i] = stringToAdd;
}
return result;
}
}
}
Editor is loading...