Advertisement
Sybatron

I5-12

Mar 25th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace I5_12
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string text = Console.ReadLine();
  10.             for (int i = 0; i < text.Length; i++)
  11.             {
  12.                 if (text[i] == ' ')
  13.                 {
  14.                     int indexSpace = i + 1;
  15.                     int count = 1;
  16.                     while (text[indexSpace] == ' ')
  17.                     {
  18.                         count++;
  19.                         indexSpace++;
  20.                     }
  21.  
  22.                     string tempText = "";
  23.                     for (int j = 0; j < count; j++)
  24.                     {
  25.                         tempText += " ";
  26.                     }
  27.                     text = text.Replace(tempText, " ");
  28.                 }
  29.             }
  30.  
  31.             int countWords = 0;
  32.             int index = text.IndexOf(' ');
  33.             while (index != -1)
  34.             {
  35.                 countWords++;
  36.                 index = text.IndexOf(' ', index + 1);
  37.             }
  38.             countWords++;
  39.  
  40.             index = text.IndexOf(' ');
  41.             string[] dictionary = new string[countWords];
  42.             int tempI = 0;
  43.             int q = 0;
  44.             while (index != -1)
  45.             {
  46.                 dictionary[q] = text.Substring(tempI, index - tempI);
  47.                 tempI = index + 1;
  48.                 index = text.IndexOf(' ', index + 1);
  49.                 q++;
  50.             }
  51.             dictionary[countWords - 1] = text.Substring(tempI, text.Length - tempI);
  52.  
  53.  
  54.             for (int i = 0; i < countWords; i++)
  55.             {
  56.                 for (int j = 0; j < countWords - 1 - i; j++)
  57.                 {
  58.                     if (dictionary[j].CompareTo(dictionary[j + 1]) == 1)
  59.                     {
  60.                         string x = dictionary[j];
  61.                         dictionary[j] = dictionary[j + 1];
  62.                         dictionary[j + 1] = x;
  63.                     }
  64.                 }
  65.             }
  66.  
  67.             Console.WriteLine("Думите подредени в азбучен ред са: ");
  68.             for (int i = 0; i < dictionary.Length; i++)
  69.             {
  70.                 Console.WriteLine(dictionary[i]);
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement