Advertisement
NozdrachevNN

Untitled

Jul 8th, 2022
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 KB | None | 0 0
  1. //Microsoft (R) Visual C# Compiler version 3.4.0-beta4-19562-05 (ff930dec)
  2. //Copyright (C) Microsoft Corporation. All rights reserved.
  3.  
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9.  
  10. namespace Rextester
  11. {
  12.     public class Program
  13.     {
  14.         public static void Main(string[] args)
  15.         {
  16.             //Your code goes here
  17.            //  массив 5, 3, 8, 6, 4, 2, 9, 0
  18. //Нужно получить такой массив, в котором все числа 3, 6, 9, будут повторяться количество раз равное значению
  19. //например:5, 3, 3, 3, 8, 6, 6, 6, 6, 6, 6, 4, 2, 9, 9, 9, 9, 9, 9, 9, 9, 9,0
  20.  
  21. int [] numbers = new int[]{5, 3, 8, 6, 4, 2, 9, 0};
  22. WriteArray (numbers);
  23. int length = numbers.Length;
  24. int newLength = numbers.Length;
  25.  
  26.  
  27.            
  28. Console.WriteLine(length);
  29.  
  30. Console.WriteLine(newLength);
  31.  
  32.  
  33.            
  34. for (int i = 0; i< numbers.Length; i++)
  35. {
  36.     {
  37.          if(numbers[i] == 3)
  38.          {
  39.             newLength = newLength + 2;
  40.          }
  41.    
  42.    
  43.         else if(numbers[i] == 6)
  44.          {
  45.             newLength = newLength + 5;
  46.          }
  47.    
  48.    
  49.    
  50.          
  51.     }
  52.            
  53.            
  54.         }
  55.            
  56. Console.WriteLine(newLength);
  57.            
  58. //int x =0;
  59.            
  60. int[]newArray = new int[newLength];            
  61.  
  62.            
  63. for (int i = 0, j = 0; i < numbers.Length; i++)
  64.    
  65.  
  66. {
  67.   //  j++;
  68.     newArray[j] = numbers[i];
  69.    
  70.     {
  71.                
  72.             if (numbers[i] == 3)
  73.               {
  74.                  for (int x = 0; x <= 2; x++)
  75.                      {
  76.                      
  77.                      newArray[x] = numbers[i];
  78.                      
  79.                      }
  80.                  //newArray[j] = 3;
  81.              
  82.                 j++;
  83.                }
  84.    
  85.      
  86.    
  87.    
  88.     j++;
  89.  
  90.     }
  91.    
  92.     //
  93.    
  94. //int z =0;    
  95.      {
  96.                
  97.             if (numbers[i] == 6)
  98.               {
  99.                  for (int z = 0; z <= 6; z++)
  100.                      {
  101.                      
  102.                      newArray[j] = numbers[i];
  103.                      
  104.                      }
  105.                  //newArray[j] = 3;
  106.              
  107.                 j++;
  108.                }
  109.    
  110.      
  111.    
  112.    
  113.   //  j++;
  114.  
  115.     }
  116.     //
  117.    
  118.    
  119.    
  120.    
  121.    
  122.     }
  123.  
  124.  
  125. WriteArray(newArray);
  126.  
  127. void WriteArray(int[] array)
  128. {
  129.     for (int i = 0; i< array.Length; i++)
  130.     {
  131.         Console.Write(array[i] + " ");
  132.     }
  133.         Console.WriteLine();
  134. }
  135.         }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement