Advertisement
Guest User

1.6

a guest
Oct 18th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         class getStringInfo
  8.         {
  9.             public static void doTheThings(string str)
  10.             {
  11.                 int notWhiteSpaceSymbols = 0, wordCount = 0;
  12.                 double symbolToWordRatio;
  13.                 string lastCharsWord = string.Empty;
  14.  
  15.                 for (int i = 1; i < str.Length; i++) //проверка последнего символа потом еще или как подумай
  16.                 {
  17.                     if (char.IsLetterOrDigit(str[i - 1]) == true)
  18.                     {
  19.                         notWhiteSpaceSymbols++;
  20.                         if (char.IsLetterOrDigit(str[i]) == false)
  21.                         {
  22.                             wordCount++;
  23.                             lastCharsWord += Convert.ToString(str[i - 1]);
  24.                         }
  25.                     }
  26.                     else if (char.IsWhiteSpace(str[i - 1]) == false)
  27.                         notWhiteSpaceSymbols++;
  28.                 }
  29.  
  30.                 symbolToWordRatio = notWhiteSpaceSymbols / wordCount;
  31.  
  32.                 Console.WriteLine("Количество слов: {0};", wordCount);
  33.                 Console.WriteLine("Количество символов без пробелов: {0};", notWhiteSpaceSymbols);
  34.                 Console.WriteLine("Соотношение количество символов без пробелов к количеству слов: {0};", symbolToWordRatio);
  35.                 Console.WriteLine("Слово из последних символов слов: \"{0}\";", lastCharsWord);
  36.             }
  37.         }
  38.         static void Main(string[] args)
  39.         {
  40.             const string teststr = "Lorem Ipsum - это текст-\"рыба\", часто используемый в печати и вэб-дизайне.";
  41.             string str = Console.ReadLine();
  42.  
  43.             getStringInfo.doTheThings(teststr);
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement