Nikolcho

3 задача

May 20th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 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 _03.Period
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Console.WriteLine("Broi chisla: ");
  15.             int n = int.Parse(Console.ReadLine());
  16.             int[] nums = new int[n];
  17.             int[] period = new int[n];
  18.  
  19.             for (int i = 0; i < n; i++)
  20.             {
  21.                 nums[i] = int.Parse(Console.ReadLine());
  22.             }
  23.             // 3, 1, 2, 3, 1, 2, 3
  24.             int times = 0;
  25.             int skip = 0;
  26.             for (int i = 0; i < n; i++)
  27.             {
  28.                 int cur = nums[i];
  29.                 if (nums.Count(nm => nm == cur) > 1)
  30.                 {
  31.                     period[0] = cur;
  32.                     break;
  33.                 }
  34.                 else
  35.                 {
  36.                     skip++;
  37.                 }
  38.             }
  39.             for (int i = 1 + skip; i < n; i++)
  40.             {
  41.                 if (nums[i] != period[0])
  42.                 {
  43.                     period[i - skip] = nums[i];
  44.                 }
  45.                 else
  46.                 {
  47.                     break;
  48.                 }
  49.             }
  50.             bool did = false;
  51.             bool end = false;
  52.  
  53.             for (int i = 0 + skip; i < n;)
  54.             {
  55.                 for (int j = 0; j < period.Count(p => p != 0); j++)
  56.                 {
  57.                     if (nums[i] == period[j])
  58.                     {
  59.                         did = true;
  60.                         if (i + 1 >= n)
  61.                         {
  62.                             end = true;
  63.                             if (period.Count(p => p != 0) > 1 && nums[i] == period[0])
  64.                             {
  65.                                 did = false;
  66.                             }
  67.                             break;
  68.                         }
  69.                     }
  70.                     else
  71.                     {
  72.                         did = false;
  73.                         break;
  74.                     }
  75.                     i++;
  76.                 }
  77.                 if (did)
  78.                 {
  79.                     times++;
  80.                     if (end)
  81.                     {
  82.                         break;
  83.                     }
  84.                 }
  85.                 else
  86.                 {
  87.                     break;
  88.                 }
  89.             }
  90.  
  91.             Console.WriteLine(times);
  92.         }
  93.     }
  94. }
Add Comment
Please, Sign In to add comment