Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace I5_12
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i] == ' ')
- {
- int indexSpace = i + 1;
- int count = 1;
- while (text[indexSpace] == ' ')
- {
- count++;
- indexSpace++;
- }
- string tempText = "";
- for (int j = 0; j < count; j++)
- {
- tempText += " ";
- }
- text = text.Replace(tempText, " ");
- }
- }
- int countWords = 0;
- int index = text.IndexOf(' ');
- while (index != -1)
- {
- countWords++;
- index = text.IndexOf(' ', index + 1);
- }
- countWords++;
- index = text.IndexOf(' ');
- string[] dictionary = new string[countWords];
- int tempI = 0;
- int q = 0;
- while (index != -1)
- {
- dictionary[q] = text.Substring(tempI, index - tempI);
- tempI = index + 1;
- index = text.IndexOf(' ', index + 1);
- q++;
- }
- dictionary[countWords - 1] = text.Substring(tempI, text.Length - tempI);
- for (int i = 0; i < countWords; i++)
- {
- for (int j = 0; j < countWords - 1 - i; j++)
- {
- if (dictionary[j].CompareTo(dictionary[j + 1]) == 1)
- {
- string x = dictionary[j];
- dictionary[j] = dictionary[j + 1];
- dictionary[j + 1] = x;
- }
- }
- }
- Console.WriteLine("Думите подредени в азбучен ред са: ");
- for (int i = 0; i < dictionary.Length; i++)
- {
- Console.WriteLine(dictionary[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement