Advertisement
stanevplamen

02.09.01.05.OneTaskNotEnough

Jun 19th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class OneTaskNotEnough
  5. {
  6.     static void CalculatingLamps(List<int> lampCollection, int step)
  7.     {
  8.         int number = 0;
  9.         if (lampCollection.Count == 1)
  10.         {
  11.             number = lampCollection[0];
  12.             Console.WriteLine(number);
  13.  
  14.         }
  15.  
  16.         List<int> newCollection = new List<int>();
  17.         if (lampCollection.Count > 1)
  18.         {
  19.             for (int i = 0; i < lampCollection.Count; i++)
  20.             {
  21.                 if (i % step == 0)
  22.                 {
  23.                     continue;
  24.                 }
  25.                 else
  26.                 {
  27.                     newCollection.Add(lampCollection[i]);
  28.                 }
  29.  
  30.             }            
  31.             CalculatingLamps(newCollection, step + 1);
  32.         }      
  33.  
  34.     }
  35.  
  36.  
  37.     static void CheckForBounding(string inputRoute)
  38.     {
  39.         int counterLs = 0;
  40.         int counterRs = 0;
  41.         foreach (char letter in inputRoute)
  42.         {
  43.             if (letter == 'L')
  44.             {
  45.                 counterLs++;
  46.             }
  47.             if (letter == 'R')
  48.             {
  49.                 counterRs++;
  50.             }
  51.         }
  52.  
  53.         if (counterLs == counterRs)
  54.         {
  55.             Console.WriteLine("unbounded");
  56.         }
  57.         else
  58.         {
  59.             Console.WriteLine("bounded");
  60.         }
  61.     }
  62.  
  63.     static void Main()
  64.     {
  65.  
  66.         // first part
  67.         int lamps = int.Parse(Console.ReadLine()); //12;
  68.         //DateTime start = DateTime.Now;
  69.         List<int> lampCollection = new List<int>();
  70.         int counter = 2;
  71.         for (int i = 2; i <= lamps; i = i + 2)
  72.         {
  73.             counter++;
  74.             if (counter == 3)
  75.             {
  76.                 counter = 0;
  77.                 continue;
  78.             }
  79.             lampCollection.Add(i);
  80.         }
  81.         int step = 4;
  82.         CalculatingLamps(lampCollection, step);
  83.  
  84.         //TimeSpan duration = DateTime.Now - start;
  85.         //Console.WriteLine("That took " + duration.TotalMilliseconds + " ms");
  86.  
  87.         // second part
  88.         string inputRouteOne = Console.ReadLine().ToUpper();        // "L".ToUpper();
  89.         CheckForBounding(inputRouteOne);
  90.         string inputRouteTwo = Console.ReadLine().ToUpper();        //"SRSL".ToUpper();
  91.         CheckForBounding(inputRouteTwo);
  92.  
  93.        
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement