Loading...

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

Elena123456 avatar Elena123456 235 Точки

10. SoftUni Course Planning- 66/100

Ако някой има време и желание, моля да погледне кода ми, ще бъда благодарна, тъй като за жалост на упражнението, което гледах се отказаха да дебъгват докрай за да открият защо се получава несъответствие в аутпутите. Аз дебъгвах няколко часа, но така и не успях да остраня проблемите, които забелязвам:

-при "Swap" командата: понякога се преместват и упражненията, а понякога се пропускат;

-проблем при изпечатването, ако имаме примерно "Data Types", защото очевидно не чета правилно входната команда, ако тя се състой от две думи;

-мисля, че отстраних проблема при командата "Exercise" и сега работи както трябва;

-предпоследният тест е RunTime error и с мойте тестове не мога да разбера къде бих могла да изляза от границите на масива;

 

И все пак ако  има по-кратко и логично решение бих се радвала поне да знам, че същестува, дори и ако все още е част от материала, който не съм учила.

условие: https://softuni.bg/trainings/resources/officedocument/49579/lists-exercise-csharp-fundamentals-may-2020/2830

https://judge.softuni.bg/Contests/Compete/Index/1211#9

https://pastebin.com/Wq3ihC9F  66/100

 

 

 

 

Тагове:
0
Programming Fundamentals 27/09/2020 20:02:58
nickwork avatar nickwork 657 Точки

Сещам се за тази задача..

пускам ти моето решение 

https://pastebin.com/UqmN5K7h

1
Axiomatik avatar Axiomatik 2422 Точки

The main-idea behind this exercise is to push the student to start using private helper-methods, because even if your code is 500 lines or more you can still handle the information when everything is sliced up into smaller pieces of code. If all of the code is placed into one single method, then debugging becomes a nightmare.

Best,

using System;
using System.Linq;
using System.Collections.Generic;

namespace softuniCoursePlanning
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> courseSchedule = Console.ReadLine().Split(", ").ToList();
            List<string> filter = courseSchedule.FindAll(course => course == "Data Types");
            string command = Console.ReadLine();

            while (command != "course start")
            {
                string[] operation = command.Split(':');
                switch (operation[0])
                {
                    case "Add":
                        AddOperator(operation[1], courseSchedule); break;
                    case "Insert":
                        InsertOperator(operation[1], int.Parse(operation[2]), courseSchedule); break;
                    case "Remove":
                        RemoveOperator(operation[1], courseSchedule); break;
                    case "Exercise":
                        ExerciseOperator(operation[1], courseSchedule); break;
                    case "Swap":
                        SwapOperator(operation[1], operation[2], courseSchedule); break;
                    default:
                        break;
                }
                command = Console.ReadLine();
            }
            int counter = 1;

            foreach (var item in courseSchedule)
            {
                Console.WriteLine($"{counter}.{item}");
                counter++;
            }
        }

        static List<string> AddOperator(string title, List<string> courseSchedule)
        {
            bool lessonExist = courseSchedule.Exists(course => course == title);
            if (lessonExist)
            {
                return courseSchedule;
            }
            courseSchedule.Add(title);
            return courseSchedule;
        }

        static List<string> InsertOperator(string title, int index, List<string> courseSchedule)
        {
            bool lessonExist = courseSchedule.Exists(course => course == title);
            if (lessonExist)
            {
                return courseSchedule;
            }
            courseSchedule.Insert(index, title);
            return courseSchedule;
        }

        static List<string> RemoveOperator(string title, List<string> courseSchedule)
        {
            bool courseExist = courseSchedule.Exists(course => course == title);
            bool exerciseExist = courseSchedule.Exists(exercise => exercise == title + "-Exercise");

            if (courseExist)
            {
                courseSchedule.Remove(title);
            }
            if (exerciseExist)
            {
                courseSchedule.Remove(title + "-Exercise");
            }
            return courseSchedule;
        }

        static List<string> ExerciseOperator(string title, List<string> courseSchedule)
        {
            bool courseExist = courseSchedule.Exists(course => course == title);
            bool exerciseExist = courseSchedule.Exists(course => course == title + "-Exercise");
            int courseIndex = courseSchedule.FindIndex(course => course == title);
            int exerciseIndex = courseIndex + 1;
            if (courseExist && exerciseExist == false)
            {
                courseSchedule.Insert(exerciseIndex, title + "-Exercise");
            }
            else if (courseExist == false)
            {
                courseSchedule.Add(title);
                courseSchedule.Add(title + "-Exercise");
            }
            return courseSchedule;
        }

        static List<string> SwapOperator(string title1, string title2, List<string> courseSchedule)
        {
            bool course1Exist = courseSchedule.Exists(course => course == title1);
            bool course2Exist = courseSchedule.Exists(course => course == title2);
            bool exercise1Exist = courseSchedule.Exists(course => course == title1 + "-Exercise");
            bool exercise2Exist = courseSchedule.Exists(course => course == title2 + "-Exercise");
            int course1Index = courseSchedule.FindIndex(course => course == title1);
            int course2Index = courseSchedule.FindIndex(course => course == title2);
            int exercise1Index = courseSchedule.FindIndex(course => course == title1 + "-Exercise");
            int exercise2Index = courseSchedule.FindIndex(course => course == title2 + "-Exercise");

            if (course1Exist && course2Exist)
            {
                string oldElement = courseSchedule[course1Index];
                courseSchedule[course1Index] = courseSchedule[course2Index];
                courseSchedule[course2Index] = oldElement;
                course1Index = courseSchedule.FindIndex(course => course == title1);
                course2Index = courseSchedule.FindIndex(course => course == title2);

                if (exercise1Exist && exercise2Exist)
                {
                    string oldElement2 = courseSchedule[exercise1Index];
                    courseSchedule[exercise1Index] = courseSchedule[exercise2Index];
                    courseSchedule[exercise2Index] = oldElement2;
                }
                else if (exercise1Exist)
                {
                    string oldElement4 = courseSchedule[exercise1Index];
                    courseSchedule.Remove(oldElement4);
                    courseSchedule.Insert(course1Index + 1, oldElement4);
                }
                else if (exercise2Exist)
                {
                    string oldElement5 = courseSchedule[exercise2Index];
                    courseSchedule.Remove(oldElement5);
                    courseSchedule.Insert(course2Index + 1, oldElement5);
                }

            }

            return courseSchedule;
        }
    }
}

2
Elena123456 avatar Elena123456 235 Точки

Hi,

thanks to both of you!

I've handled your solutions and was debuging until 3 a.m. Unfortunately for this exercise I have up 10 hours debuging.

I've refactored my code and now I think everything is working without print. Can somebody please have a look at my "Console.WriteLine()", only this, not the rest of the lines.

https://pastebin.com/gJydF5Ud

All the best!

Eli

2
28/09/2020 13:57:24
Axiomatik avatar Axiomatik 2422 Точки

From what I can see, the code seems to be working, only the final-output is not working as it should, but this is caused by the way you are splitting up the initial input string at line 11 (Monodevelop). When used with List<string> scheduleList = Console.ReadLine().Split(", ").ToList(); instead of List<string> scheduleList = Console.ReadLine().Split(", ".ToCharArray()).ToList();, then the input comes out just fine.

Best,

 

Output with Monodevelop:

1.Arrays

2.Data

3.Types

4.

5.Objects

6.

7.Databases

Expected Output with standard input-split:

1.Arrays

2.Data Types

3.Objects

4.Databases

1
Elena123456 avatar Elena123456 235 Точки

Thanks again!

It didn't crossed my mind that the root of the problem was  MonoDevelop. 

For Christmas I plan to buy a new laptop with Windows 10 and maybe same of my problems would be resolved. :)

https://pastebin.com/pYQTesny -  88/100 with Test #9 (Time limit), but I'am confident the logic is corect and the code works.

By the way I have watched the webinar with Iordan Georgeiv. It's very useful about habits and how brain works, thanks a lot. While I was studying six years at the university  I did my best to develop and learn helthy habits about discipline and studing. I familiar with the book "Eat the frog" and how important is to do hardest things first in the morning. For this I'am studying in the morning and going to work after 3 o'clock. I love to recomend you "The Willpower Instinct: How Self-Control Works, Why It Matters, and What You Can Do to Get More of It " and "The Psychology of Performance: How to Be Your Best in Life".

Best regards!

Eli

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