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;
- namespace KawaiiDesu
- {
- class Program
- {
- static List<Action> actions = new List<Action>() { Path1, Path2, Path3, Path4, Path5, Path6, Path7, PassInput, averageStudents, tallestDude, randomNum, EETisCrap, hardOne, hardTwo, hardThree, hardFour };
- static void Main(string[] args)
- {
- while (true)
- {
- try
- {
- var num = (int)vignekit.numInput("\n Index cesty: ");
- if (num > actions.Count-1) throw new Exception(" Neplatný index (0-"+(actions.Count-1)+")");
- actions[num].Invoke();
- }
- catch (Exception ex)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(ex.Message);
- Console.ResetColor();
- }
- }
- }
- static void Path1()
- {
- Random gen = new Random();
- int over5 = 0, even = 0, total = 0;
- for (var i = 0; i < 10; i++)
- {
- int value = gen.Next(11);
- if (value > 5) over5++;
- if (value % 2 == 0) even++;
- total += value;
- }
- Console.WriteLine(@" {0} jich bylo větší než 5.
- {1} jich bylo sudých.
- {2} je jejich součet.", over5, even, total);
- }
- static void Path2()
- {
- Random gen = new Random();
- int counter = 0;
- for (var i = 0; i < 10; i++) {
- int value = gen.Next(-100, 101);
- if (value > 10 && value < 50) counter++;
- }
- Console.WriteLine(" {0} čísel je v rozhraní 10-50", counter);
- }
- static void Path3(){
- int counter = 0;
- for (var i = 0; i < 10; i++)
- {
- float value = vignekit.numInput(" Zadej " + (i + 1) + ". číslo: ");
- if (value > 10 && value < 50) counter++;
- }
- Console.WriteLine(" {0} čísel je v rozhraní 10-50", counter);
- }
- static void Path4(){
- Random gen = new Random();
- HashSet<int> nums = new HashSet<int>();
- while (nums.Count < 6)
- {
- nums.Add(gen.Next(1, 50));
- }
- Console.WriteLine("\n [ {0} ]", string.Join(", ", nums));
- }
- static void Path5()
- {
- Random gen = new Random();
- int attempts = 10, wrong = 0;
- for (var i = 0; i < attempts; i++) {
- int num1 = gen.Next(11), num2 = gen.Next(11);
- int answer = (int)vignekit.numInput(" "+num1+" * "+num2+" = ");
- if (answer != num1 * num2)
- {
- wrong++;
- Console.WriteLine(" Špatně...");
- }
- }
- Console.WriteLine(" {0} chyb", wrong);
- }
- static void Path6(){
- int dice = new Random().Next(1, 7), attempts = 0;
- while (true)
- {
- int val = (int)vignekit.numInput(" Co jsem hodil za číslo? ");
- if (val == dice)
- break;
- else
- attempts++;
- Console.WriteLine(" Špatně.");
- }
- Console.WriteLine(" Správně! Uhádls to na {0}. pokus", attempts+1);
- }
- static void Path7(){
- Random gen = new Random();
- int illc = (int)vignekit.numInput(" Kolikrát mám hodit kostkou? ");
- int[] calc = new int[6];
- for (var i = 0; i < illc; i++) {
- calc[gen.Next(0, 6)]++;
- }
- for (var i = 0; i < calc.Length; i++) {
- Console.WriteLine(" {0} padlo {1}%", i + 1, (float)calc[i] / illc *100);
- }
- }
- //index 7 - 1. priklad
- static void PassInput()
- {
- bool accepted = false;
- int attempts = 0;
- string pass = "hehe";
- while (attempts < 2) {
- Console.Write("\n Heslo: ");
- accepted = Console.ReadLine() == pass;
- if (accepted) break;
- Console.WriteLine("Invalid Password."); attempts++;
- }
- if (accepted)
- Console.WriteLine("Permission granted.");
- else
- Console.WriteLine("Permission denied.");
- }
- //index 8 - 2. priklad
- static void averageStudents()
- {
- List<int> nums = new List<int>();
- int lastNum = 1;
- while (lastNum != 0) {
- lastNum = (int)vignekit.numInput(" Zadej počet žáků: ");
- if (lastNum > 0) nums.Add(lastNum);
- }
- Console.WriteLine("Průměrný počet žáků ve třídě: {0}", (nums.Count == 0) ? "nikdo do školy nechodí." : ((int)nums.Average()).ToString());
- }
- //index 9 - 5. priklad
- static void tallestDude() {
- bool keepGoing = true;
- string recordName = ""; float recordHeight = -1;
- while (keepGoing) {
- Console.Write("\n\nZadej jméno studenta: ");
- string name = Console.ReadLine();
- if (string.IsNullOrWhiteSpace(name)) break;
- float height = vignekit.numInput("Zadej výšku studenta: ");
- if (height > recordHeight)
- {
- recordName = name;
- recordHeight = height;
- }
- }
- Console.WriteLine(" Nejvyšší člověk je {0}, který je {1}m vysoký", recordName, recordHeight);
- }
- //index 10 - 7. priklad
- static void randomNum() {
- int dice = new Random().Next(1, 11), attempts = 0;
- while (true)
- {
- int val = (int)vignekit.numInput(" Co jsem si vymyslel za číslo? ");
- if (val == dice)
- break;
- else
- attempts++;
- Console.WriteLine(" Špatně.");
- }
- Console.WriteLine(" Správně! Uhádls to na {0}. pokus", attempts + 1);
- }
- //index 11 - 8. priklad
- static void diceThrower() {
- Random gen = new Random(); int attempts = 0;
- while (true) {
- attempts++;
- int newNum = gen.Next(1, 7);
- if (newNum == 6) break;
- }
- Console.WriteLine(" Padlo mi to po {0} pokusech.", attempts);
- }
- //index 12 - 3. priklad
- static void EETisCrap()
- {
- List<int> nums = new List<int>(); int lastNum = 1, overboard = 0;
- while (lastNum != 0) {
- lastNum = (int)vignekit.numInput(" Zadej částku: ");
- if (lastNum > 0) nums.Add(lastNum);
- if (lastNum > 100) overboard++;
- }
- Console.WriteLine("Utratil jsi {0}Kč, z toho bylo {1} nákupů nad 100Kč.", nums.Sum(), overboard);
- }
- //index 13 - 1. tezky priklad
- static void hardOne()
- {
- string output = "";
- for (var i = 0; i < 10; i++) {
- output += (i+1).ToString();
- Console.WriteLine(output);
- }
- }
- //index 14 - 2. tezky priklad
- static void hardTwo()
- {
- Random gen = new Random();
- for (var i = 0; i < 20; i++) {
- Console.WriteLine(new String('*', gen.Next(20)));
- }
- }
- //index 15 - 3. tezky priklad
- static void hardThree()
- {
- List<int> primes = new List<int>();
- for (var i = 0; i < 1000; i++) {
- if (vignekit.isPrime(i)) primes.Add(i);
- }
- Console.WriteLine("\n Prvočísla v rozhraní 0-1000:\n [ {0} ] ", string.Join(", ", primes));
- }
- //index 16 - 4. tezky priklad
- static void hardFour()
- {
- for (var i = 0; i < 10; i++)
- {
- List<int> nums = new List<int>();
- for (var y = 0; y < 10; y++)
- {
- nums.Add((y + 1) * (i+1));
- }
- Console.WriteLine("[ {0} ]", string.Join(", ", nums));
- }
- }
- }
- class vignekit
- {
- public static float numInput(string prompt = "Zadej číslo: ", string invalid = "Neplatné číslo.")
- {
- bool isValid = false; float val = 0; //celkem na tom nezalezi, z loopu by nevylezl
- while (!isValid)
- {
- Console.Write("\n{0}", prompt);
- isValid = float.TryParse(Console.ReadLine(), out val);
- if (!isValid)
- {
- Console.WriteLine(invalid);
- }
- }
- return val;
- }
- public static bool isPrime(float n)
- {
- if (n <= 1) return false;
- for (var i = 2; i < n; i++) {
- if (n % i == 0) return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement