Skip to content

Instantly share code, notes, and snippets.

@Toumash
Created January 27, 2018 11:20
Show Gist options
  • Save Toumash/4b5d8a729ff88f2f323c9fac73eee564 to your computer and use it in GitHub Desktop.
Save Toumash/4b5d8a729ff88f2f323c9fac73eee564 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace zaliczenie
{
class Program
{
static void Main(string[] args)
{
var rozwiazania = new List<Action>() { Mediana, KonwersjaNaBinarne, Miesiace, ArabskiNaRzymski };
for(int i=0;i< rozwiazania.Count;i++){
Console.WriteLine("{0}. {1}",i,rozwiazania[i].Method.Name);
}
Console.Write("Wybor:");
int wybor = Convert.ToInt32(Console.ReadLine());
if (wybor <= rozwiazania.Count && wybor > 0)
{
rozwiazania[wybor - 1].Invoke();
}
else
{
Console.WriteLine("Niepoprawny numer zadania");
}
}
static void Mediana()
{
int x;
int[] elements;
#if DEBUG
x = 5;
elements = new[] { 1, 2, 3, 4, 5 };
#else
x = Convert.ToInt32(Console.ReadLine());
elements = new int[x];
for (int i = 0; i < x; i++)
{
elements[i] = Convert.ToInt32(Console.ReadLine());
}
#endif
for (int i = 0; i < elements.Length; i++)
{
for (int j = 0; j < elements.Length - 1; j++)
{
if (elements[j] > elements[j + 1])
{
int temp = elements[j];
elements[j] = elements[j + 1];
elements[j + 1] = temp;
}
}
}
if (elements.Length % 2 == 0)
{
var mediana = (elements[elements.Length / 2] + elements[elements.Length / 2 - 1]) / 2.0;
Console.WriteLine("Mediana=" + mediana);
for (int i = 0; i < elements.Length; i += 2)
{
Console.WriteLine("{0} {1}", elements[i], elements[i + 1]);
}
}
else
{
var mediana = elements[elements.Length / 2];
Console.WriteLine("Mediana=" + mediana);
for (int i = 0; i < elements.Length - 1; i += 2)
{
Console.WriteLine("{0} {1}", elements[i], elements[i + 1]);
}
Console.WriteLine("{0}", elements[elements.Length - 1]);
}
}
static void KonwersjaNaBinarne()
{
int x;
#if DEBUG
x = 5;
#else
x = Convert.ToInt32(Console.ReadLine());
#endif
Console.WriteLine(ToBinary(x));
}
public static int ToBinary(int n)
{
if (n == 1) return 1;
if (n == 0) return 0;
string liczba = "";
while (n > 0)
{
liczba = n % 2 + liczba;
n = n / 2;
}
return int.Parse(liczba);
}
static void Miesiace()
{
int miesiac = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Miesiąc nr. {0} to {1}", miesiac, MiesiacSlownie(miesiac));
}
static string MiesiacSlownie(int numerMiesiaca)
{
switch (numerMiesiaca)
{
case 1: return "Styczeń";
case 2: return "Luty";
case 3: return "Marzec";
case 4: return "Kwiecień";
case 5: return "Maj";
case 6: return "Czerwiec";
case 7: return "Lipiec";
case 8: return "Sierpień";
case 9: return "Wrzesień";
case 10: return "Październik";
case 11: return "Listopad";
case 12: return "Grudzień";
default:
return "niepoprawny miesiąc";
}
}
static void ArabskiNaRzymski()
{
int x;
#if DEBUG
x = 15;
#else
x = Convert.ToInt32(Console.ReadLine());
#endif
var sb = new StringBuilder();
while (x > 0)
{
if (x >= 1000)
{
sb.Append("M");
x -= 1000;
}
else if (x >= 900)
{
sb.Append("CM");
x -= 900;
}
else if (x >= 500)
{
sb.Append("D");
x -= 500;
}
else if (x >= 400)
{
sb.Append("CD");
x -= 400;
}
else if (x >= 100)
{
sb.Append("C");
x -= 100;
}
else if (x >= 50)
{
sb.Append("L");
x -= 50;
}
else if (x >= 10)
{
sb.Append("X");
x -= 10;
}
else if (x >= 9)
{
sb.Append("IX");
x -= 9;
}
else if (x >= 5)
{
sb.Append("V");
x -= 5;
}
else if (x >= 4)
{
sb.Append("IV");
x -= 4;
}
else if (x >= 1)
{
sb.Append("I");
x -= 1;
}
}
Console.WriteLine(sb.ToString());
}
}
}
@Toumash
Copy link
Author

Toumash commented Jan 27, 2018

wczytaj liczbe
stworz tablice o takiej liczbuie elementow
znajdz mediane i wyswietl
i wydrukuj liczby na ekranie w dwoch kolumnach

  1. pobierz od usera liczbe naturalna i zamien na dwojkowy
  2. zdefiniuj tablice 12 elementow z mieiacami. podajemu numer i program ma podac jego nazwe slownie
  3. konwersja z arabskiego na rzymski

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment