Advertisement
Guest User

Untitled

a guest
May 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 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.  
  7. namespace ConsoleApplication11
  8. {
  9.     class Program
  10.     {
  11.         static void NactiText(ref string txt)
  12.         {
  13.             Console.WriteLine("Zadejte vstupni text:");
  14.             txt = Console.ReadLine();
  15.         }
  16.  
  17.         static bool JeCislice(char z)
  18.         {
  19.  
  20.             return (z >= '0' && z <= '9');
  21.         }
  22.         static void Zpracuj(string txt)
  23.         {
  24.  
  25.             char pred = '0';
  26.             int pocetcisel = 0;
  27.             for (int i = 0; i < txt.Length; i++)
  28.             {
  29.                 if (JeCislice(pred) && (!(JeCislice(txt[i]))))
  30.                     pocetcisel++;
  31.                 pred = txt[i];
  32.             }
  33.             Console.WriteLine("Pocet celych cisel ve vete {0} je {1}", txt, pocetcisel);
  34.         }
  35.  
  36.         static void Main(string[] args)
  37.         {
  38.             char volba = '9';
  39.             string vstup = "";
  40.             do
  41.             {
  42.                 Console.Clear();
  43.                 if (volba == '1' || volba == '0') NactiText(ref vstup);
  44.                 if (volba == '2' || volba == '0') Zpracuj(vstup);
  45.                 Console.WriteLine("Program pocita pocet celych cisel v zadani. Napr. asdfsafd45.98asd je vysledek 2.\n\n1..Zadat vstupni text\n2..Zpracovat\n----------------\n9..Konec");
  46.                 volba = Console.ReadKey().KeyChar;
  47.             } while (volba != '9');
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement