  CvetelinP 2 Точки

## Number Array проблем Programming Fundamentals Mid Exam - 30 June 2019 Group 1

Привет ,;

може ли решение на задачата:

Create a program that helps you keep track of a number array. First, you are going to receive the numbers оn a single line, separated by space, in the following format:

"{number1} {number2} {number3}… {numbern}"

Then you will start receiving commands until you read the "End" message. There are five possible commands:

• "Switch {index}"
• Find the number on this index in your collection, if the index exists, and switch its sign (negative <-> positive).
• "Change {index} {value}"
• Replace the number on the given index with the number given, if the index exists.
• "Sum Negative"
• Print the sum of all negative numbers.
• "Sum Positive"
• Print the sum of all positive numbers.
• "Sum All"
• Print the sum of all numbers.

In the end, print the positive numbers on a single line, keeping in mind that 0 is positive, separated by a single space in the following format:

"{number1} {number2} {number3}… {numbern}"

## Input

• On the 1st line you are going to receive the numbers of the array (always integers), separated by a single space.
• On the next lines, until the "End" command is received, you will be receiving commands.

## Output

• Print the tasks in the format described above.

Тагове:
0 knoteva 1025 Точки

Здравей,

Ето и едно работещо решение.

https://pastebin.com/VrEqhjJu

1 krum_43 220 Точки

Console.WriteLine(string.Join(" ", list.Where(x => x >= 0)));

Няма ли да изведеш един излишен интервал преди първият елемент на масива?

В условието искат:

"{number1} {number2} {number3}… {numbern}"

0 knoteva 1025 Точки

Ами не. За това и използвам join. :) Ако имаме лист с елемти 3, 4 и 5 и напишем  Console.WriteLine(string.Join(", ", list); ще се отпечата: 3, 4, 5

1 krum_43 220 Точки

Да,

Така е.

:)

0