Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5.     class Program
  6.     {
  7.         static int returnIndex(int i, int value, int[] y)
  8.         {
  9.             if (i > 29)
  10.                 return -1;
  11.             else if (i % 3 == 0 && value < 0 && y[i] == -999)
  12.                 return i;
  13.             else if (i % 3 == 1 && value == 0 && y[i] == -999)
  14.                 return i;
  15.             else if (i % 3 == 2 && value > 0 && y[i]==-999)
  16.                 return i;
  17.             else
  18.                 return returnIndex(++i, value,y);
  19.  
  20.         }
  21.         static void Main(string[] args)
  22.         {
  23.             /*
  24.              * Trvac e vector -0+
  25.              */
  26.             int k = 0;
  27.             int[] x = new int[10];
  28.             int[] y = new int[10*3];
  29.  
  30.             for (int i = 0; i < x.Length; i++)
  31.             {
  32.                 x[i] = new Random().Next(-5, 5);
  33.                 x[2] = 0;
  34.                 Console.Write($"{x[i]} ");
  35.             }
  36.             for (int i = 0; i < y.Length; i++)
  37.             {
  38.                 y[i] = -999;
  39.             }
  40.             Console.WriteLine();
  41.             for (int i = 0; i < x.Length; i++)
  42.             {
  43.                 if (x[i] < 0)
  44.                 {
  45.                     k = returnIndex(0, x[i],y);
  46.                     y[k] = x[i];
  47.                 }
  48.                 else if (x[i] == 0)
  49.                 {
  50.                     k = returnIndex(0, x[i],y);
  51.                     y[k] = x[i];
  52.  
  53.                 }
  54.                 else if (x[i] > 0)
  55.                 {
  56.                     k = returnIndex(0, x[i],y);
  57.                     y[k] = x[i];
  58.  
  59.                 }
  60.             }
  61.             for (int i = 0; i < y.Length; i++)
  62.             {
  63.                 if (y[i] != -999)
  64.                 {
  65.                     Console.Write(y[i] + " ");
  66.                 }
  67.             }
  68.             ////0 -1 2 3 -4 0 1
  69.  
  70.  
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement