Untitled

 avatar
unknown
plain_text
4 years ago
3.7 kB
4
Indexable
using System;
using System.Text.RegularExpressions;

namespace Kolos1
{
    class Program
    {

        static void zad1() //łańcuch znaków
        {
            Console.WriteLine("Podaj tablice znakow, oddzielając je spacją: ");
            string ciag = Console.ReadLine();
            Console.WriteLine("Podaj znak: ");
            string znak = Console.ReadLine();
            string[] spearator = { " " };
            int count = ciag.Length; //liczy spacje ale chyba to nie problem
            String[] tab = ciag.Split(spearator, count, StringSplitOptions.RemoveEmptyEntries); //w dlugosci(count) uzywa separatora zeby rozdzielil na tablice
            int suma = 0;
            foreach (string s in tab)
            {
                if (s == znak) //funnkcja z googla sprawdza czy string s jest litera
                {
                    suma++;
                }
                else
                {
                    continue;
                }
            }
            Console.WriteLine("Twoja znak wystapil: {0} razy", suma);
        }

        static void zad2() //tablica liczb
        {
            Console.WriteLine("Podaj rozmiar tablicy: ");
            int rozmiar = int.Parse(Console.ReadLine());
            
            Console.WriteLine("Podaj tablice cyfr, daj enter po kazdej cyfrze: ");
            int[] ciag= new int [rozmiar]; //idk jak zrobic gdy nie wiem ile ma tablica
            for (int i =0; i < rozmiar; i++)
            {
                ciag[i] = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("Podaj cyfre: ");
            int cyfra = int.Parse(Console.ReadLine());
            int suma = 0;
            for(int j = 0; j < ciag.Length; j++)
            {
                if(cyfra == ciag[j])
                {
                    suma++;
                }
                else
                {
                    continue;
                }
            }
            Console.WriteLine("Twoja cyfra wystapila: {0} razy", suma);

        }
        
        static void zad3()
        {
            Console.WriteLine("Podaj rozmiar tablicy: ");
            uint rozmiar = uint.Parse(Console.ReadLine());
            var rand = new Random();
            int Min = 0;
            int Max = 99;

            int[] tab = new int[rozmiar];
            for (int i = 0; i < rozmiar; i++)
            {
                tab[i] = rand.Next(Min, Max);
            }
            Console.WriteLine("Twoja tablica:");
            Array.ForEach(tab, Console.WriteLine); //wypisanie
        }

        static void zad4()
        {
            Console.WriteLine("Podaj rozmiar tablicy: ");
            int rozmiar = int.Parse(Console.ReadLine());

            Console.WriteLine("Podaj tablice cyfr, daj enter po kazdej cyfrze: ");
            int[] ciag = new int[rozmiar]; //idk jak zrobic gdy nie wiem ile ma tablica
            for (int i = 0; i < rozmiar; i++)
            {
                ciag[i] = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("Podaj rozmiar nowej tablicy < od poprzedniego: ");
            int nowyRozmiar = int.Parse(Console.ReadLine());
            int[] tab = new int[nowyRozmiar];
            for (int j=0; j < nowyRozmiar; j++)
            {
                tab[j] = ciag[j];
            }
            Console.WriteLine("Twoja nowa tablica:");
            Array.ForEach(tab, Console.WriteLine);
        }

        static void Main(string[] args)
        {
            //zad1();
            //zad2();
            //zad3();
            //zad4();
        }
    }
}
Editor is loading...