Advertisement
abasar

arrays 3/1/16

Jan 3rd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.98 KB | None | 0 0
  1. //Amit Lazar
  2. //#1
  3.             int N;
  4.             N = int.Parse(Console.ReadLine());
  5.             int[] a = new int[N];
  6.             for (int i = 0; i < a.Length; i++)
  7.                 a[i] = int.Parse(Console.ReadLine());
  8.             int j = 0;
  9.             bool vector;
  10.             if (a[0] == 1)
  11.                 vector = true;
  12.             else
  13.                 vector = false;
  14.             while (j < a.Length - 1 && vector == true)
  15.             {
  16.                 if (a[j + 1] - a[j] != 1)
  17.                     vector = false;
  18.                 else
  19.                     j++;
  20.             }
  21.             Console.WriteLine(vector);
  22.  
  23. //#2
  24. const int N = 6;
  25.             double[] a = new double[N];
  26.             for (int i = 0; i < a.Length; i++)
  27.                 a[i] = double.Parse(Console.ReadLine());
  28.             double[] b = new double[N];
  29.             for (int i = 0; i < a.Length; i++)
  30.                 b[i] = a[i];
  31.             int j = 1;
  32.             while (j < a.Length)
  33.             {
  34.                 if (a[j] > a[j - 1])
  35.                 {
  36.                     double holder = a[j];
  37.                     a[j] = a[j - 1];
  38.                     a[j - 1] = holder;
  39.                     if (j != 1)
  40.                         j--;
  41.                 }
  42.                 else
  43.                 {
  44.                     j++;
  45.                 }
  46.             }
  47.             for (int i = 0; i < a.Length; i++)
  48.             {
  49.                 j = 0;
  50.                 while (b[j] != a[i])
  51.                     j++;
  52.                 j++;
  53.                 Console.Write("{0, -5}", j);
  54.             }
  55.  
  56. //#3
  57.             int[] a = new int[15];
  58.             for (int i = 0; i < a.Length; i++)
  59.                 a[i] = 0;
  60.             int play, ammount, total = 0; ;
  61.             Console.Write("Enter the play number: ");
  62.             play = int.Parse(Console.ReadLine());
  63.             Console.Write("Enter the ammount of tickets: ");
  64.             ammount = int.Parse(Console.ReadLine());
  65.             while (play != 0 && ammount != 0)
  66.             {
  67.                 total += ammount;
  68.                 play--;
  69.                 a[play] += ammount;
  70.                 Console.Write("Enter the play number: ");
  71.                 play = int.Parse(Console.ReadLine());
  72.                 Console.Write("Enter the ammount of tickets: ");
  73.                 ammount = int.Parse(Console.ReadLine());
  74.             }
  75.             for (int i = 0; i < a.Length; i++)
  76.             {
  77.                 double percent = a[i] * 100 / total;
  78.                 Console.WriteLine(percent);
  79.             }
  80.  
  81. //#4
  82.             public static void Main(string[] args) {
  83.         int[] a = new int[365];
  84.         Random rnd = new Random();
  85.                 for (int i = 0; i < a.Length; i++)
  86.                 a[i] = rnd.Next(100);
  87.         int rainy = 0, row = 1, max = 0;
  88.         for (int i = 1; i < a.Length; i++)
  89.         {
  90.         if (a[i] == a[i - 1])
  91.         {
  92.             if (row == 2)
  93.             {
  94.                 rainy++;
  95.             }
  96.                 row++;
  97.         }
  98.             else
  99.                 row = 1;
  100.             if (a[i] > max)
  101.                 max = i;
  102.         }
  103.         Console.WriteLine(rainy);
  104.         Console.WriteLine(max);
  105.  
  106. //#5
  107.             bool[] a = new bool[1000];  //true for open, false for closed
  108.             for (int i = 0; i < a.Length; i++)
  109.                 a[i] = true;
  110.             for (int i = 6; i < a.Length; i++)
  111.             {
  112.                 if (i % 2 == 0)
  113.                 {
  114.                     if (a[i])
  115.                         a[i] = false;
  116.                     else
  117.                         a[i] = true;
  118.                 }
  119.             }
  120.             for (int i = 2; i < a.Length; i++)
  121.             {
  122.                 if (i - 2 % 3 == 0)
  123.                 {
  124.                     if (a[i])
  125.                         a[i] = false;
  126.                     else
  127.                         a[i] = true;
  128.                 }
  129.             }
  130.             for (int i = 0; i < a.Length; i++)
  131.             {
  132.                 if (a[i])
  133.                     Console.WriteLine(i);
  134.             }
  135.  
  136. //#6
  137.             int[] N = new int[10];
  138.             int[] M = new int[10];
  139.             for (int i = 0; i < 10; i++)
  140.                 N[i] = int.Parse(Console.ReadLine());
  141.             int end = 9, start = 0;
  142.             for (int i = 0; i < N.Length; i++)
  143.             {
  144.                 if (N[i] % 2 == 0)
  145.                 {
  146.                     M[end] = N[i];
  147.                     end--;
  148.                 }
  149.                 else
  150.                 {
  151.                     M[start] = N[i];
  152.                     start++;
  153.                 }
  154.             }
  155.             for (int i = 0; i < M.Length; i++)
  156.                 Console.Write("{0,-3}", M[i]);
  157.  
  158. //#7
  159.             int[] a = new int[6];
  160.             for (int i = 0; i < a.Length; i++)
  161.                 a[i] = int.Parse(Console.ReadLine());
  162.             int[] b = new int[a.Length + 1];
  163.             int sum = 0;
  164.             b[0] = sum;
  165.             for (int i = 1; i < a.Length + 1; i++)
  166.             {
  167.                 sum += a[i - 1];
  168.                 b[i] = sum;
  169.             }
  170.             for (int i = 0; i < b.Length; i++)
  171.                 Console.Write("{0, -3}", b[i]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement