Kriss_7777

ВИДИН_Модул-02_Упр-04_файлове-13-14-15-16

Mar 7th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.87 KB | None | 0 0
  1. // ВИДИН - МОДУЛ_02; Упражнение 04 ; DOC-ФАЙЛОВЕ 13, 14, 15 и 16;
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. namespace Upr_04_Spisak_s_imena
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             /*
  14.  
  15.             // Упражнение_04 (папка 4), DOC-файл 13 //////////////////////////////////////////////////////////////////////
  16.             //-------------------------------------------
  17.  
  18.          // 2. Списък от имена ..........................................................
  19.                        List<string> myList1 =   Console.ReadLine().
  20.                                                Split(" ").
  21.                                                //Sеlect(*.Parse).
  22.                                                ToList();
  23.  
  24.                        Console.WriteLine(String.Join("; ", myList1));
  25.  
  26.  
  27.  
  28.  
  29.          // 3. Списък от имена II .......................................................
  30.                        List<string> myList2 = Console.ReadLine().
  31.                                                Split(", ").
  32.                                                //Select(*.Parse).
  33.                                                ToList();
  34.  
  35.  
  36.                        foreach(string myItem in myList2)
  37.                        {
  38.                            string[] separatedItem = myItem.Split(" ");
  39.                            Console.WriteLine(separatedItem[1] + " " + separatedItem[0]);
  40.  
  41.                        }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.              // Упражнение_04 (папка 4), DOC-файл 14 //////////////////////////////////////////////////////////////////////
  48.              //--------------------------------------------
  49.  
  50.  
  51.          // 2. Списък от четни числа...........................
  52.  
  53.                        List<int> myList3 = Console.ReadLine().
  54.                                                Split(" ").
  55.                                                Select(int.Parse).
  56.                                                ToList();
  57.  
  58.                        foreach(int myNum in myList3)
  59.                        {
  60.                            if(myNum % 2 ==0)
  61.                            {
  62.                                Console.Write(myNum + " ");
  63.                            }
  64.                        }
  65.  
  66.  
  67.  
  68.                        // 3. Списък от крайности ...........................
  69.  
  70.                        List<int> myList4 = Console.ReadLine().
  71.                                               Split(" ").
  72.                                               Select(int.Parse).
  73.                                               ToList();
  74.  
  75.                        int Min = myList4.Min();
  76.                        int Max = myList4.Max();
  77.  
  78.                        foreach (int myNum in myList4)
  79.                        {
  80.                            if (myNum == Min || myNum == Max)
  81.                            {
  82.                                Console.Write(myNum + " ");
  83.                            }
  84.                        }
  85.  
  86.            
  87.         // 4.   Максимална поредица еднакви числа ...........................
  88.             List<int> myList5 = Console.ReadLine().
  89.                                         Split(" ").
  90.                                         Select(int.Parse).
  91.                                         ToList();
  92.  
  93.             int currentValue = 0;
  94.             int currentStart = 0;
  95.             int currentLength = 0;
  96.  
  97.             int bestValue = 0;
  98.             int bestStart = 0;
  99.             int bestLength = 0;
  100.  
  101.  
  102.             for (int i = 0; i < myList5.Count-1; i++) // Обхождаме списъка и увеличаваме съответния брояч
  103.             {
  104.                 currentValue = myList5[i];
  105.                 currentStart = i;
  106.                 currentLength = 0;
  107.  
  108.                 while (currentValue == myList5[i] && i < myList5.Count-1)
  109.                 {
  110.                     currentLength++;
  111.                     i++;
  112.  
  113.  
  114.                     if (bestLength < currentLength)
  115.                     {
  116.                         bestLength = currentLength;
  117.                         bestStart = currentStart;
  118.                         bestValue = currentValue;
  119.                     }
  120.                 }
  121.             }
  122.  
  123.  
  124.             for (int j = 1; j <= bestLength; j++)
  125.             {
  126.                 Console.Write(bestValue + " ");
  127.             }
  128.  
  129.  
  130.  
  131.  
  132.    // 5.    Сума на обърнати числа ...........................
  133.  
  134.             List<string> myList6 = Console.ReadLine().
  135.                                         Split(" ").
  136.                                         //Select(int.Parse).
  137.                                         ToList();
  138.             int sum = 0;
  139.  
  140.  
  141.             for (int i = 0; i < myList6.Count; i++)
  142.             {
  143.                 char[] currString = myList6[i].ToCharArray();// Всеки от елементите на списъка се превръща в
  144.                                                              // масив орт символи
  145.  
  146.                 Array.Reverse(currString); // Реверсира се масива
  147.  
  148.                 string revString = new string(currString); // Масива се конвертира в стринг
  149.  
  150.                 int curValue = int.Parse(revString); // Стринга се парсва към целочислен
  151.  
  152.  
  153.                 sum += curValue; // сумират се реверсираните стойности
  154.  
  155.             }
  156.  
  157.  
  158.             Console.WriteLine(sum);
  159.  
  160.    
  161.  
  162.  
  163.  
  164.             // Упражнение_04 (папка 4), DOC-файл 16 //////////////////////////////////////////////////////////////////////
  165.             //--------------------------------------------
  166.  
  167.             // 3.Числа квадрати ................................
  168.  
  169.             List<int> myList7 = Console.ReadLine().
  170.                                         Split(" ").
  171.                                         Select(int.Parse).
  172.                                         ToList();
  173.  
  174.             List<int> squares = new List<int>();
  175.             int i = 0;
  176.  
  177.             foreach (int item in myList7)
  178.             {
  179.                 if (Math.Sqrt(item) == (int)Math.Sqrt(item))
  180.                 {
  181.                     squares.Add(item);
  182.                 }
  183.  
  184.             }
  185.  
  186.  
  187.  
  188.             // squares = squares.Sort((a, b) => b.CompareTo(a));
  189.             squares.Sort();
  190.             squares.Reverse();
  191.  
  192.  
  193.             foreach (var myItem in squares)
  194.             {
  195.                 Console.Write(myItem + " ");
  196.             }
  197.  
  198.  
  199.  
  200.             // 4. Брой числа ................................
  201.             List<int> myList8 = Console.ReadLine().
  202.                                         Split(" ").
  203.                                         Select(int.Parse).
  204.                                         ToList();
  205.  
  206.             int[] numbers = new int[myList8.Count];
  207.            
  208.             myList8.Sort();
  209.  
  210.             for (int i = 0; i <= myList8.Count-1; i++)
  211.             {
  212.                 numbers[i] = myList8[i];
  213.             }
  214.  
  215.             // Console.WriteLine(String.Join(" ", numbers));
  216.  
  217.             int j = 0;
  218.             int counter = 0;
  219.             int current = numbers[j];
  220.  
  221.             for (j = 0;j < numbers.Length-1; j++)
  222.             {
  223.                 counter = 0;
  224.  
  225.                 while (current == numbers[j] )
  226.                 {
  227.                     counter++;
  228.                     j++;
  229.  
  230.                     if (j == numbers.Length) { break; }
  231.                 }
  232.  
  233.                 Console.WriteLine(current + " -> " + counter);
  234.  
  235.                 if (j < numbers.Length - 1) { current = numbers[j]; }
  236.  
  237.                     j--;
  238.             }
  239.            
  240.    
  241.     */
  242.  
  243.             //  1 1 1 1 2 2 2 4 4 4 4 4 3 3 3 7 7 7 8 8 8 8 8 8
  244.  
  245.         }
  246.     }
  247. }
Add Comment
Please, Sign In to add comment