Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Zadacha3_7
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Задаем длину массива:
- int count;
- Console.Write("Введите длину массива: ");
- count = Convert.ToInt32(Console.ReadLine());
- //Создаем и заполняем массив:
- int[] array = new int[count];
- for (int i = 0; i < count; i++)
- {
- Console.WriteLine("Введите значение для эл. ["+i+"]: ");
- array[i] = Convert.ToInt32(Console.ReadLine());
- }
- Console.WriteLine("Выводим наш массив: ");
- //Выводим наш массив:
- for (int i = 0; i < count; i++)
- {
- Console.Write(array[i]+" ");
- }
- //Считаем кол. нулей:
- int countZero = 0;
- for (int i = 0; i < count; i++)
- {
- if (array[i] == 0) countZero++;
- }
- Console.WriteLine("\n"+"Кол. нулей равно: " + countZero);
- //Заводим массив из индексов нулей:
- int [] arrayZero = new int[countZero];
- int indZer = 0;
- for (int i = 0; i < count; i++)
- {
- if (array[i] == 0)
- {
- arrayZero[indZer] = i;
- indZer++;
- }
- }
- Console.WriteLine("Выводим наш массив из инд. нулей: ");
- //Выводим наш массив:
- for (int i = 0; i < countZero-1; i++)
- {
- Console.Write(arrayZero[i] + " ");
- }
- int [] arrayNotZero = new int[countZero];
- int indTmp = -1;
- int tmpSum = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] == 0)
- {
- if (indTmp != -1)
- {
- arrayNotZero[indTmp] = tmpSum;
- }
- tmpSum=0;
- indTmp++;
- }
- else
- {
- tmpSum+=array[i];
- }
- }
- for (int i = 0; i < countZero; i++)
- {
- Console.WriteLine(arrayNotZero[i] + " ");
- }
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement