Advertisement
barybatle

sadasd

Nov 21st, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.66 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 lancuchy_znakow_zadania
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //zad1
  14.  
  15.             string s1 = "kompas, GPS, krem, kurtka, podkoszulek, koszulka, kamizelka, rękawiczki, czapka, latarka, telefon, pas";
  16.  
  17.             string s2 = s1.Replace(" ", "");
  18.  
  19.             string[] tab1 = s2.Split(',');
  20.  
  21.             int max, min, idxmin, idxmax;
  22.  
  23.             min = tab1[0].Length;
  24.  
  25.             max = idxmin = idxmax = 0;
  26.  
  27.             for (int i = 0; i < tab1.Length; i++)
  28.             {
  29.                 if (tab1[i].Length > max)
  30.                 {
  31.                     max = tab1[i].Length;
  32.                     idxmax = i;
  33.                 }
  34.                 if (tab1[i].Length < min)
  35.                 {
  36.                     min = tab1[i].Length;
  37.                     idxmin = i;
  38.                 }
  39.             }
  40.             string slowomax = tab1[idxmax];
  41.  
  42.             string slowomin = tab1[idxmin];
  43.            
  44.             Console.WriteLine("Min = \"{0}\"\nMax = \"{1}\"",slowomin, slowomax);
  45.  
  46.             //zad2
  47.  
  48.             string s3 = "34;54;23;45;64;23;55;77;33;22;66;44;33;20";
  49.  
  50.             string[] tab2 = s3.Split(';');
  51.  
  52.             int suma = 0;
  53.  
  54.             for (int j = 0; j < tab2.Length; j++)
  55.             {
  56.                 int liczba = int.Parse(tab2[j]);
  57.  
  58.                 suma += liczba;
  59.             }
  60.             Console.WriteLine(suma);
  61.  
  62.             //zad3
  63.  
  64.             Random rnd = new Random();
  65.  
  66.             Console.WriteLine("Podaj liczbę elementów tablicy: ");
  67.  
  68.             int liczbaele = int.Parse(Console.ReadLine());
  69.  
  70.             double[] tabzad3 = new double[liczbaele];
  71.  
  72.             for (int e = 0; e < tabzad3.Length; e++)
  73.             {
  74.                 tabzad3[e] = rnd.Next(10, 21) / 5.00;
  75.  
  76.                 string zad3b = tabzad3[e] + "|";
  77.  
  78.                 string[] tabzad3b = new string[liczbaele];
  79.  
  80.                 for (int r = 0; r < tabzad3b.Length; r++)
  81.                 {
  82.                     tabzad3b[r] = zad3b;
  83.                 }
  84.                
  85.             }
  86.            
  87.  
  88.            
  89.            
  90.             //zad 4
  91.  
  92.             string zad4 = "Marcin Ania Daniel Piotr Ela Ewa Małgosia Zenon";
  93.  
  94.             string[] tabzad4 = zad4.Split(' ');
  95.  
  96.             int minzad4 = tabzad4[0].Length;
  97.  
  98.             int idxminzad4 = 0;
  99.  
  100.             for (int z = 0; z < tabzad4.Length; z++)
  101.             {
  102.                 if (!tabzad4[z].EndsWith("a"))
  103.                 {
  104.                     Console.WriteLine("- {0}", tabzad4[z]);
  105.                 }
  106.             }
  107.             for (int p = 0; p < tabzad4.Length; p++)
  108.             {
  109.                 if ((!tabzad4[p].EndsWith("a")) && (tabzad4[p].Length < minzad4))
  110.                 {
  111.                     idxminzad4 = p;
  112.                     Console.WriteLine("Najkrótsze męskie imię to: {0}", tabzad4[idxminzad4]);
  113.                     break;
  114.                 }
  115.             }
  116.            
  117.             //zad 5
  118.  
  119.             string zad5 = "To jest tekst oryginalny ktory nalezy zamienic na tzw format CamelCase";
  120.  
  121.             string[] tabzad5 = zad5.Split(' ');
  122.  
  123.             for (int c = 0; c < tabzad5.Length; c++)
  124.             {
  125.                 char[] tabzad5b = tabzad5[c].ToCharArray();
  126.  
  127.                 for (int v = 0; v < tabzad5b.Length; v++)
  128.                 {
  129.                     if (v == 0)
  130.                     {
  131.                         char.ToUpper(tabzad5b[v]);
  132.                     }
  133.                 }
  134.             }
  135.  
  136.  
  137.                 Console.ReadKey();
  138.         }
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement