Advertisement
Levi0227

5. heti házi

Oct 10th, 2023 (edited)
1,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.03 KB | Source Code | 0 0
  1. namespace PMPHF004_P99J7Y
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             string E = Console.ReadLine();
  8.             char[] chararray = E.ToCharArray();
  9.  
  10.             #region 1. lépés
  11.             if (E.Length > 1)
  12.             {
  13.                 string elsolep = "";
  14.                 for (int i = 1; i < chararray.Length; i += 2)
  15.                 {
  16.                     elsolep += chararray[i];
  17.                 }
  18.  
  19.                 int hossz = elsolep.Length - 1;
  20.                 string megfordit = "";
  21.                 while (hossz >= 0)
  22.                 {
  23.                     megfordit += elsolep[hossz];
  24.                     hossz--;
  25.                 }
  26.                 char[] elsoarray = megfordit.ToCharArray();
  27.                 int n1 = 0;
  28.                 for (int i = 0; i < chararray.Length; ++i)
  29.                 {
  30.                     if (i % 2 == 1)
  31.                     {
  32.                         chararray[i] = elsoarray[n1];
  33.                         n1++;
  34.                     }
  35.                 }
  36.             }
  37.             #endregion 1. lépés
  38.  
  39.             #region 2. lépés
  40.             if (E.Length > 2)
  41.             {
  42.                 string masodik = "";
  43.                 for (int i = 2; i < chararray.Length; i += 3)
  44.                 {
  45.                     masodik += chararray[i];
  46.                 }
  47.  
  48.                 char firstchar = masodik[0];
  49.                 for (int i = 5; i < chararray.Length; i += 3)
  50.                 {
  51.                     chararray[i - 3] = chararray[i];
  52.                 }
  53.  
  54.                 int index = chararray.Length;
  55.                 if (chararray.Length % 3 == 0)
  56.                 {
  57.                     index = chararray.Length - 1;
  58.                 }
  59.                 else if (chararray.Length % 3 == 2)
  60.                 {
  61.                     index = chararray.Length - 3;
  62.                 }
  63.                 else
  64.                 {
  65.                     index = chararray.Length - 2;
  66.                 }
  67.                 chararray[index] = firstchar;
  68.             }
  69.             #endregion 2. lépés
  70.  
  71.             #region 3. lépés
  72.             if (E.Length > 3)
  73.             {
  74.                 string harmadik = "";
  75.                 for (int i = 3; i < chararray.Length; i += 4)
  76.                 {
  77.                     harmadik += chararray[i];
  78.                 }
  79.                
  80.                 chararray[3] = harmadik[harmadik.Length - 1];
  81.                 int k = 0;
  82.                 for (int i = 7; i < chararray.Length; i += 4)
  83.                 {
  84.                     chararray[i] = harmadik[k];
  85.                     k++;
  86.                 }
  87.             }
  88.             #endregion 3. lépés
  89.  
  90.             Console.Clear();
  91.  
  92.             #region 4. lépés
  93.             string szo = new string(chararray);
  94.             string[] szavak = szo.Split(' ');
  95.             int[] count = new int[szavak.Length];
  96.             for (int i = 0; i < szavak.Length; i++)
  97.             {
  98.                 count[i] = szavak[i].Length;
  99.             }
  100.  
  101.             int length = count.Length-1;
  102.             string reverse = "";
  103.             while (length >= 0)
  104.             {
  105.                 reverse += count[length]+" ";
  106.                 length--;
  107.             }
  108.             for (int i = 0; i < count.Length; i++)
  109.             {
  110.                 count[i] = int.Parse(reverse.Split(" ")[i]);
  111.             }
  112.  
  113.             if (chararray.Length > 1)
  114.             {
  115.                 string megoldas = "";
  116.                 for (int i = 0; i < szavak.Length; i++)
  117.                 {
  118.                     megoldas += szavak[i];
  119.                 }
  120.                 int f = 0;
  121.                 for (int i = 0; i < szavak.Length; i++)
  122.                 {
  123.                     megoldas = megoldas.Insert(count[i] + f, " ");
  124.                     f += count[i]+1;
  125.                 }
  126.                 Console.Write(megoldas.Remove(megoldas.Length - 1));
  127.             }
  128.             else
  129.             {
  130.                 Console.Write(chararray);
  131.             }
  132.             #endregion 4. lépés
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement