axeefectushka

Untitled

Feb 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.VisualBasic;
  7.  
  8. namespace Reversing_and_Combining_Text
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string text = "abc def ghi jkl";
  15.             List<string> str= new List<string> { };
  16.             List<string> str2 = new List<string> { };
  17.             str = text.Split(' ').ToList();
  18.             int n=str.Count();
  19.             int k;
  20.             char temp;
  21.             int spaces = n - 1;
  22.             while( n !=1)
  23.             {
  24.                
  25.                 for (int i = 0; i < n; i++)
  26.                 {
  27.                     char[] arr = str[i].ToCharArray();
  28.                     k = arr.Length;
  29.                     for (int j = 0, h = k - 1; j < h; j++, h--)
  30.                     {
  31.                         temp = arr[j];
  32.                         arr[j] = arr[h];
  33.                         arr[h] = temp;
  34.                     }
  35.                     str[i] = String.Concat(arr);
  36.                     arr = null;
  37.                 }
  38.                 for (int i = 0; i < n - 1; i++)
  39.                 {
  40.                     str[i] += str[i + 1];
  41.                 }
  42.                 for (int i = 0; i < n; i++)
  43.                 {
  44.                     if (i % 2 == 0)
  45.                     {
  46.                         str2.Add(str[i]);
  47.                     }
  48.                 }
  49.                 str.Clear();
  50.                 for (int i = 0; i < str2.Count(); i++)
  51.                 {
  52.                     str.Add(str2[i]);
  53.                 }
  54.                 str2.Clear();
  55.                 n = str.Count();
  56.             }
  57.                
  58.             string newText = string.Concat<string>(str);
  59.             Console.WriteLine(newText);
  60.         }
  61.     }
  62. }
Add Comment
Please, Sign In to add comment