Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace meres4
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Hány mérési pontot nézzünk meg?: ");
- int n = Convert.ToInt32(Console.ReadLine());
- int[] eredmenyek = setMeres(n);
- getMeres(eredmenyek);
- Console.ReadLine();
- Console.Clear();
- int max_index = legmagasabbpont(eredmenyek);
- Console.WriteLine("A legmagasabb indexe: "+ max_index + ", értéke: "+ eredmenyek[max_index]);
- int osszes_max = LegHanyszor(eredmenyek, max_index);
- Console.WriteLine("A(z) " + eredmenyek[max_index] + " összesen " + osszes_max + ". szerepelt a mérésben");
- Console.WriteLine("A leghosszabb szigethossz: " + LeghosszabbSzigetHossz(eredmenyek));
- Console.WriteLine(OttVanE(eredmenyek, legmagasabbpont(eredmenyek)));
- Console.ReadLine();
- }
- public static int[] setMeres(int n) {
- int[] temp = new int[n];
- Random r = new Random();
- for (int i = 0; i < temp.Length; i++)
- {
- int chanche = r.Next(0, 101);
- if (chanche <= 40)
- {
- temp[i] = r.Next(1, 11);
- }
- else
- {
- temp[i] = 0;
- }
- }
- return temp;
- }
- public static void getMeres(int[]A)
- {
- foreach (int i in A)
- {
- Console.Write(i + ", ");
- }
- }
- public static int legmagasabbpont(int[] A)
- {
- int index = 0; int max = 0;
- for (int i = 0; i < A.Length; i++)
- {
- if (max < A[i])
- {
- max = A[i];
- index = i;
- }
- }
- return index;
- }
- public static int LegHanyszor(int[]A, int max) {
- int db = 0;
- for (int i = 0; i < A.Length; i++)
- {
- if (A[i] == A[max])
- {
- db++;
- }
- }
- return db;
- }
- public static int LeghosszabbSzigetHossz(int[]A) {
- int max = 0;
- int db = 0;
- for (int i = 0; i < A.Length; i++)
- {
- if (A[i] != 0)
- {
- db++;
- }
- else
- {
- if (db > 0)
- {
- if (db > max)
- {
- max = db;
- }
- db = 0;
- }
- }
- if (db > max)
- {
- max = db;
- }
- }
- return max;
- }
- public static Boolean OttVanE(int[] A, int max) {
- int leghosszabbszakaserteke = LeghosszabbSzigetHossz(A);
- int jobbmax = 0; int balmax = 0;
- int index = max;
- while (index < max+leghosszabbszakaserteke && A[index] > 0)
- {
- jobbmax++;
- index++;
- }
- index = max;
- while (index > max - leghosszabbszakaserteke && A[index] > 0)
- {
- balmax++;
- index--;
- }
- int eredmeny = balmax + jobbmax + 1;
- return eredmeny == leghosszabbszakaserteke;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement