Advertisement
NozdrachevNN

Untitled

Jul 8th, 2022
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 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.            
  44. Console.WriteLine(newLength);
  45.            
  46. //int x =0;
  47.            
  48. int[]newArray = new int[newLength];            
  49.  
  50.            
  51. for (int i = 0, j = 0; i < numbers.Length; i++, j++)
  52.     {
  53.        
  54.         {
  55.             if (numbers[i] == 3)
  56.               {
  57.                  for (int x = 0; x < 3; x++)
  58.                      
  59.                  //newArray[j] = numbers[i];
  60.                      newArray[j] = 3;
  61.                
  62.                  j++;
  63.                }
  64.         }
  65.     newArray[j] = numbers[i];
  66.    
  67.  //   j++;
  68.    
  69.    
  70.    
  71.     }
  72.  
  73.             //}
  74.  
  75. WriteArray(newArray);
  76.  
  77. void WriteArray(int[] array)
  78. {
  79.     for (int i = 0; i< array.Length; i++)
  80.     {
  81.         Console.Write(array[i] + " ");
  82.     }
  83.         Console.WriteLine();
  84. }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement