Advertisement
Zneeky

Точки

Nov 30th, 2021
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. namespace Dots
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             //directory for example E:\Tekst.txt
  11.            
  12.             Console.WriteLine("Pleae, write the directroy of the .txt file you would like to check!\nExample:\"E:\\Tekst.txt\"");
  13.             string directory = Console.ReadLine();
  14.             string txt = File.ReadAllText(@$"{directory}");
  15.  
  16.             int comasCounter = 0;
  17.             int dotsCounter = 0;
  18.             int numbers = 0;
  19.             bool lastCharIsDigit = false;
  20.            
  21.  
  22.             foreach  (char ch in txt)
  23.             {
  24.                 if (ch == 44)
  25.                 {
  26.                     comasCounter++;
  27.                     lastCharIsDigit = false;
  28.                 }
  29.                 else if (ch == 46)
  30.                 {
  31.                     dotsCounter++;
  32.                     lastCharIsDigit = false;
  33.                 }else if (Char.IsDigit(ch) && lastCharIsDigit==false)
  34.                 {
  35.                     lastCharIsDigit = true;
  36.                     numbers++;
  37.                 }
  38.                 else if(Char.IsDigit(ch) && lastCharIsDigit == true)
  39.                 {
  40.                     lastCharIsDigit = true;
  41.                 }
  42.                 else
  43.                 {
  44.                     lastCharIsDigit = false;
  45.                 }
  46.  
  47.             }
  48.             Console.WriteLine($"Count of dots: {dotsCounter}\nCount of comas: {comasCounter}\nNumbers in txt: {numbers}");
  49.  
  50.  
  51.  
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement