Advertisement
Hakuhun

Labor 4

Oct 5th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.76 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 meres4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Write("Hány mérési pontot nézzünk meg?: ");
  14.             int n = Convert.ToInt32(Console.ReadLine());
  15.  
  16.             int[] eredmenyek = setMeres(n);
  17.             getMeres(eredmenyek);
  18.  
  19.             Console.ReadLine();
  20.             Console.Clear();
  21.  
  22.             int max_index = legmagasabbpont(eredmenyek);
  23.  
  24.             Console.WriteLine("A legmagasabb indexe: "+ max_index + ", értéke: "+ eredmenyek[max_index]);
  25.  
  26.             int osszes_max = LegHanyszor(eredmenyek, max_index);
  27.             Console.WriteLine("A(z) " + eredmenyek[max_index] + " összesen " + osszes_max + ". szerepelt a mérésben");
  28.  
  29.             Console.WriteLine("A leghosszabb szigethossz: " + LeghosszabbSzigetHossz(eredmenyek));
  30.  
  31.             Console.WriteLine(OttVanE(eredmenyek, legmagasabbpont(eredmenyek)));
  32.  
  33.             Console.ReadLine();
  34.  
  35.         }
  36.  
  37.         public static int[] setMeres(int n) {
  38.             int[] temp = new int[n];
  39.             Random r = new Random();
  40.  
  41.             for (int i = 0; i < temp.Length; i++)
  42.             {
  43.                 int chanche = r.Next(0, 101);
  44.                 if (chanche <= 40)
  45.                 {
  46.                     temp[i] = r.Next(1, 11);
  47.                 }
  48.                 else
  49.                 {
  50.                     temp[i] = 0;
  51.                 }
  52.             }
  53.  
  54.             return temp;
  55.  
  56.         }
  57.  
  58.         public static void getMeres(int[]A)
  59.         {
  60.             foreach (int i in A)
  61.             {
  62.                 Console.Write(i + ", ");
  63.             }
  64.         }
  65.  
  66.         public static int legmagasabbpont(int[] A)
  67.         {
  68.             int index = 0; int max = 0;
  69.             for (int i = 0; i < A.Length; i++)
  70.             {
  71.                 if (max < A[i])
  72.                 {
  73.                     max = A[i];
  74.                     index = i;
  75.                 }
  76.             }
  77.  
  78.             return index;
  79.         }
  80.  
  81.         public static int LegHanyszor(int[]A, int max) {
  82.             int db = 0;
  83.             for (int i = 0; i < A.Length; i++)
  84.             {
  85.                 if (A[i] == A[max])
  86.                 {
  87.                     db++;
  88.                 }
  89.             }
  90.             return db;
  91.         }
  92.  
  93.         public static int LeghosszabbSzigetHossz(int[]A) {
  94.             int max = 0;
  95.             int db = 0;
  96.             for (int i = 0; i < A.Length; i++)
  97.             {
  98.                 if (A[i] != 0)
  99.                 {
  100.                     db++;
  101.                 }
  102.                 else
  103.                 {
  104.                     if (db > 0)
  105.                     {
  106.                         if (db > max)
  107.                         {
  108.                             max = db;
  109.                         }
  110.                         db = 0;
  111.                     }
  112.                 }
  113.                 if (db > max)
  114.                 {
  115.                     max = db;
  116.                 }
  117.  
  118.             }
  119.             return max;
  120.         }
  121.  
  122.         public static Boolean OttVanE(int[] A, int max) {
  123.             int leghosszabbszakaserteke = LeghosszabbSzigetHossz(A);
  124.             int jobbmax = 0; int balmax = 0;
  125.             int index = max;
  126.             while (index < max+leghosszabbszakaserteke && A[index] > 0)
  127.             {
  128.                 jobbmax++;
  129.                 index++;
  130.             }
  131.             index = max;
  132.             while (index > max - leghosszabbszakaserteke && A[index] > 0)
  133.             {
  134.                 balmax++;
  135.                 index--;
  136.             }
  137.             int eredmeny = balmax + jobbmax + 1;
  138.  
  139.             return eredmeny == leghosszabbszakaserteke;
  140.         }
  141.  
  142.  
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement