Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace ConsoleApplication33
- {
- class Program
- {
- static int[] zjistiSamohlasky(char[] znaky, string text)
- {
- int[] stav = new int[znaky.Length];
- int pocet1 = 0;
- for (int i = 0; i < znaky.Length; i++)
- {
- foreach (char c in text)
- if (Convert.ToString(znaky[i]).Contains(c))
- {
- if (i == pocet1)
- stav[pocet1]++;
- }
- pocet1++;
- }
- return stav;
- }
- static void Main(string[] args)
- {
- bool pokr = true;
- string text = "";
- string cesta = "";
- bool plati = true;
- Console.WriteLine("Zadej cestu k souboru");
- cesta = Console.ReadLine();
- while (pokr)
- {
- Console.WriteLine("zvol operaci!");
- Console.WriteLine("------------------------");
- Console.WriteLine("-samo- pro vyhledani aeiou");
- Console.WriteLine("------------------------");
- Console.WriteLine("-vyhl- pro vlastni vyber");
- Console.WriteLine("------------------------");
- Console.WriteLine("-cel- pro soucet vsech");
- Console.WriteLine("------------------------");
- Console.WriteLine("-vyp- pro vypsani pohadky");
- Console.WriteLine("------------------------");
- Console.WriteLine("-zap- pro zapsani do pohadky");
- Console.WriteLine("------------------------");
- Console.WriteLine("-maz- pro smaazani obsahu souboru");
- Console.WriteLine("------------------------");
- string samohlasky = "";
- bool chce = true;
- string operace = Console.ReadLine();
- switch (operace)
- {
- case "samo":
- samohlasky = "aeiou";
- using (StreamReader nr = new StreamReader(cesta))
- {
- text = nr.ReadToEnd();
- nr.Close();
- }
- break;
- case "vyhl":
- Console.WriteLine("Zadej znaky, ktere chces analyzovat, bez mezer - format abcd");
- samohlasky = Console.ReadLine();
- break;
- case "cel":
- Console.WriteLine(zjistiSamohlasky("aeiou".ToArray(), text).Sum());
- chce = false;
- break;
- default:
- Console.WriteLine("Nezvolili jste zadnou volbu. Prejete si program ukoncit? Jednicku pro ano cokoliv jineho - ne");
- if (Console.ReadLine() != "1")
- Environment.Exit(0);
- else chce = false;
- break;
- case "vyp":
- try
- {
- using (StreamReader nr = new StreamReader(cesta))
- {
- text = nr.ReadToEnd();
- nr.Close();
- }
- plati = false;
- }
- catch (Exception ex)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(ex.Message);
- Console.ResetColor();
- plati = true;
- }
- chce = false;
- Console.WriteLine(text);
- break;
- case "zap":
- //using (StreamWriter nc = new StreamWriter(cesta))
- //{
- // n
- // nc.Close();
- //}
- Console.WriteLine("Zadej, co chces pripsat");
- using (StreamWriter w = File.AppendText(cesta))
- {
- w.WriteLine(Console.ReadLine());
- }
- chce = false;
- break;
- case "maz":
- using (var fs = new FileStream(@cesta, FileMode.Truncate))
- {
- fs.Close();
- }
- chce = false;
- break;
- }
- int pocet = 0;
- char[] znaky = samohlasky.ToArray();
- if (chce)
- {
- Console.WriteLine("Pocet znaku:");
- for (int i = 0; i < znaky.Length; i++)
- Console.WriteLine("{0}: {1}", znaky[i], zjistiSamohlasky(znaky, text)[i]);
- }
- Console.WriteLine("Chces pokracovat? Dej 1 jinak cokoliv jineho");
- if (Console.ReadLine() != "1")
- pokr = false;
- else Console.Clear();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement