Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

razihanna avatar razihanna 7 Точки

C# Задача 7. List Manipulation Advanced - Lab

Здравейте,

Mоже ли да проверите защо получавам 90/100? и къде е грешката

Благодаря,

Lists - Lab - SoftUni Judge

решението:

7. List Manipulation Advanced - Pastebin.com

Next, we are going to implement more complicated list commands, extending the previous task. Again, read a list and keep reading commands until you receive "end":

Contains {number} – check if the list contains the number and if so - print "Yes", otherwise print "No such number".
PrintEven – print all the even numbers, separated by a space.
PrintOdd – print all the odd numbers, separated by a space.
GetSum – print the sum of all the numbers.
Filter {condition} {number} – print all the numbers that fulfill the given condition. The condition will be either '<', '>', ">=", "<=".

After the end command, print the list only if you have made some changes to the original list. Changes are made only from the commands from the previous task.

Example

Input

Output

2 13 43 876 342 23 543

Contains 100

Contains 543

PrintEven

PrintOdd

GetSum

Filter >= 43

Filter < 100

end

No such number

Yes

2 876 342

13 43 23 543

1842

43 876 342 543

2 13 43 23

 

Предишната:

6.List Manipulation Basics

Write a program that reads a list of integers. Then until you receive "end", you will receive different commands:

Add {number}: add a number to the end of the list.
Remove {number}: remove a number from the list.
RemoveAt {index}: remove a number at a given index.
Insert {number} {index}: insert a number at a given index.

Note: All the indices will be valid!

When you receive the "end" command, print the final state of the list (separated by spaces).

Example

Input

Output

4 19 2 53 6 43

Add 3

Remove 2

RemoveAt 1

Insert 8 3

end

4 53 6 8 43 3

 

Тагове:
0
C# Fundamentals
Axiomatik avatar Axiomatik 2422 Точки

The code looks OK, I think the last error comes from the print-validation that is given for this assignment:

"After the end command, print the list only if you have made some changes to the original list. Changes are made only from the commands from the previous task."

Try to check with your list of numbers if any changes have really occured, by copying the numbers to a second list and at the end compare the two lists (I have checked their elements counts and total sum). Keep in mind that changes can be undone (removing and adding back the same number), which is probably why using a simple counter might not work and tracking the changes to your list.

Validition from your code:

            if (counter > 0)
            {
                Console.WriteLine(string.Join(" ", num));
            }

 

Validation which I used:

            if (modInput.Count != input.Count || totalSumInput != totalSumModInput)
            {
                Console.WriteLine(string.Join(" ", modInput));
            }

 

Best,

 

 

 

1
razihanna avatar razihanna 7 Точки

Thank you for your reply

Best regards

1
krum_43 avatar krum_43 750 Точки

Maybe it's a loophole that breaks the code.
It is interesting whether there is a variant in which the number and sum of the elements are equal and the collections are different.

Best,

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.