Advertisement
Grafundzijus

text_array

May 1st, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. /*
  4. * Parašykite metodą, kuris priima tekstų masyvą kaip argumentą,
  5. * o grąžina masyvą tekstų, turinčių daugiausiai iš eilės pasikartojančių raidžių.
  6. */
  7.  
  8. namespace text_array
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int count = 0;
  15.  
  16.  
  17.             //teksto masyvas.
  18.             string[] text_array;
  19.             text_array = new string[]
  20.             { "aaabbccc", "kkaaccc", "ggldeerrr", "emmm", "haha hhhhha", "asgdkggggd" };
  21.  
  22.             string[] str_array = new string[10];
  23.  
  24.             Text_To_Array(text_array, count, str_array);
  25.             foreach (string text in str_array)
  26.                 Console.WriteLine(str_array);
  27.         }
  28.  
  29.         static string[] Text_To_Array(string[] text_array, int count, string[] str_array)
  30.         {
  31.  
  32.            
  33.             count = 0;
  34.            
  35.  
  36.             foreach (string text in text_array)
  37.             {
  38.  
  39.                 for (var i = 0; i < text.Length; i++)
  40.                 {
  41.                     int it_count = 1;
  42.                     for (int j = i + 1; j < text.Length; j++)
  43.                     {
  44.                         if (text[i] != text[j])
  45.                             break;
  46.                         it_count++;
  47.  
  48.                      }
  49.  
  50.                     //Patikrinama ar iteracijų kiekis didesnis nei esamas.
  51.                     if (it_count > count)
  52.                     {
  53.                         //jei iteracijų kiekis yra didesnis už esamą, perrašoma esamu.
  54.                         count = it_count;
  55.  
  56.                         List<string> str_list = new List<string>();
  57.  
  58.                         str_list.Add(text);
  59.                         str_array = str_list.ToArray();
  60.  
  61.                     }
  62.                    
  63.                 }
  64.                
  65.             }
  66.            
  67.             return str_array;
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement