7. List Manipulation Advanced
Здравейте, бих била много благодарна, ако някой види защо в тази задача във вижуъл студио всичко излиза, както е по условието, а в джъдж ми дава 50 точки.
Става дума за последната задача от лаба за листове.
Ето кода:
https://pastebin.com/88YRTw7K?fbclid=IwAR2wHdBRPusrybwTy5hgxe9DNvtf08uG7C0eaiMgkWafRoaYAcWn1e_BeKU
Ето и условието:
7. List Manipulation Advanced
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.
Благодаря!
Здравейте моля за малко помощ получавам 80/100 https://pastebin.com/CsvzpFbh
Благодаря предварително
На същата задача ми дава 80/100
някой може ли да помогне
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
List<int> myList = Console.ReadLine()
.Split()
.Select(int.Parse)
.ToList();
string inputPrim = "";
int counterMyListCount = myList.Count;
int counterOfPreviosTask = 0;
while ((inputPrim = Console.ReadLine()) != "end")
{
string[] input = inputPrim
.Split()
.ToArray();
string command = input[0];
if (command == "Add")
{
counterOfPreviosTask++;
int currentDidgit = int.Parse(input[1].ToString());
myList.Add(currentDidgit);
}
else if (command == "Remove")
{
counterOfPreviosTask++;
int currentDidgit = int.Parse(input[1].ToString());
myList.Remove(currentDidgit);
}
else if (command == "RemoveAt")
{
counterOfPreviosTask++;
int currentIndex = int.Parse(input[1].ToString());
myList.RemoveAt(currentIndex);
}
else if (command == "Insert")
{
counterOfPreviosTask++;
int currentDidgit = int.Parse(input[1].ToString());
int currentIndex = int.Parse(input[2].ToString());
myList.Insert(currentIndex, currentDidgit);
}
if (command == "Contains")
{
int currentDidgit = int.Parse(input[1]);
if (myList.Contains(currentDidgit))
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No such number");
}
} // end command == Contains
else if (command == "PrintEven")
{
List<int> secondList = myList
.Where(x => x % 2 == 0)
.ToList();
Console.WriteLine(string.Join(" ", secondList));
} // end PrintEven
else if (command == "PrintOdd")
{
List<int> secondList = myList
.Where(x => x % 2 == 1)
.ToList();
Console.WriteLine(string.Join(" ", secondList));
} // end PrintOdd
else if (command == "GetSum")
{
int currentDidgit = myList.Sum();
Console.WriteLine("{0}", currentDidgit);
} // end GetSum
else if (command == "Filter")
{
int curretValue = int.Parse(input[2]);
List<int> secondList = new List<int>();
if (input[1] == ">=")
{
Console.WriteLine(string.Join(" ", myList.Where(x => x >= curretValue)));
}
else if (input[1] == ">")
{
Console.WriteLine(string.Join(" ", myList.Where(x => x > curretValue)));
}
else if (input[1] == "<=")
{
Console.WriteLine(string.Join(" ", myList.Where(x => x <= curretValue)));
}
else if (input[1] == "<")
{
Console.WriteLine(string.Join(" ", myList.Where(x => x < curretValue)));
}
} // end Filter
} // end While
if (counterOfPreviosTask > 0 && counterMyListCount != myList.Count)
{
Console.WriteLine(string.Join(" ", myList));
}
Здравей,
if (counterOfPreviosTask > 0
&& counterMyListCount != myList.Count)За да се принтира трябва да има промяна/и в листа. Няма условие да бъдат с различна дължина.
Това написах аз.
https://pastebin.com/gX3uKCKJ
https://pastebin.com/BxTvp91G
може ли малко помощ? не намирам грешката
Привет!
Някои може ли да удари едно рамо с решението ми:
https://pastebin.com/QYhts6wH
Принтирането на PrintEven и PrintOdd завършва с интервал след последната принтирано число - по условие си пише, че трябва да има интервал след всяка цифра. Мога да напиша числата отговарящи на съответното условие да се насипват в нов лист и да изпечатвам него на конзолата, но пак ще дава същия проблем при печатането на празен интервал след последната цифра.
Също според Judge не минава на нов ред, въпреки че съм сложил Environment.NewLine и на моя Visual Studio-то си принтира на нов ред без проблем.
Искам да открия пропуските в моя код, виждам че има дадени решения по-горе в темата.