Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Microsoft (R) Visual C# Compiler version 3.4.0-beta4-19562-05 (ff930dec)
- //Copyright (C) Microsoft Corporation. All rights reserved.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- //Your code goes here
- // массив 5, 3, 8, 6, 4, 2, 9, 0
- //Нужно получить такой массив, в котором все числа 3, 6, 9, будут повторяться количество раз равное значению
- //например:5, 3, 3, 3, 8, 6, 6, 6, 6, 6, 6, 4, 2, 9, 9, 9, 9, 9, 9, 9, 9, 9,0
- int [] numbers = new int[]{5, 3, 8, 6, 4, 2, 9, 0};
- WriteArray (numbers);
- int length = numbers.Length;
- int newLength = numbers.Length;
- Console.WriteLine(length);
- Console.WriteLine(newLength);
- for (int i = 0; i< numbers.Length; i++)
- {
- {
- if(numbers[i] == 3)
- {
- newLength = newLength + 2;
- }
- else if(numbers[i] == 6)
- {
- newLength = newLength + 5;
- }
- }
- }
- Console.WriteLine(newLength);
- //int x =0;
- int[]newArray = new int[newLength];
- for (int i = 0, j = 0; i < numbers.Length; i++)
- {
- // j++;
- newArray[j] = numbers[i];
- {
- if (numbers[i] == 3)
- {
- for (int x = 0; x <= 2; x++)
- {
- newArray[x] = numbers[i];
- }
- //newArray[j] = 3;
- j++;
- }
- j++;
- }
- //
- //int z =0;
- {
- if (numbers[i] == 6)
- {
- for (int z = 0; z <= 6; z++)
- {
- newArray[j] = numbers[i];
- }
- //newArray[j] = 3;
- j++;
- }
- // j++;
- }
- //
- }
- WriteArray(newArray);
- void WriteArray(int[] array)
- {
- for (int i = 0; i< array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement