Loading...

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

Denislava91 avatar Denislava91 5 Точки

c# Tasks Planner (Programming Fundamentals Mid Exam - 30 June 2019 Group 2

Здравейте, колеги!

 

Имам нужда от вашето мнение относно Task Planner. Проблемът е, че кодът ми работи(

using System;
using System.Linq;
using System.Collections.Generic;
namespace Tasks_Planner
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tasksHours = Console.ReadLine().Split().Select(int.Parse).ToArray();

            string input = Console.ReadLine();

            int countCompleted = 0;

            int countInCompleted = 0;

            int countDropped = 0;

            while (input != "End")

            {
                string[] command = input.Split().ToArray();

                switch (command[0])

                {
                    case "Complete":

                        int index = int.Parse(command[1]);

                        if (index < 0 || index >= tasksHours.Length)

                        {
                            continue;
                        }

                        tasksHours[index] = 0;
                        break;

                    case "Change":

                        index = int.Parse(command[1]);

                        if (index < 0 || index >= tasksHours.Length)

                        {
                            continue;
                        }
                        int newTime = int.Parse(command[2]);
                        tasksHours[index] = newTime;
                        break;

                    case "Drop":
                        index = int.Parse(command[1]);
                        if (index < 0 || index >= tasksHours.Length)

                        {
                            continue;
                        }
                        tasksHours[index] = -1;

                        break;

                    case "Count":

                        string secondCommandCount = command[1];

                        if (secondCommandCount == "Completed")

                        {
                            foreach (int taskHour in tasksHours)

                            {
                                if (taskHour == 0)

                                {
                                    countCompleted++;

                                }

                            }
                            Console.WriteLine(countCompleted);

                        }

                        else if (secondCommandCount == "Incomplete")

                        {
                            foreach (int taskHour in tasksHours)

                            {
                                if (taskHour > 0)

                                {
                                    countInCompleted++;


                                }

                            }

                            Console.WriteLine(countInCompleted);
                        }

                        else if (secondCommandCount == "Dropped")

                        {
                            foreach (int taskHour in tasksHours)

                            {
                                if (taskHour < 0)

                                {
                                    countDropped++;

                                }

                            }
                            Console.WriteLine(countDropped);


                        }
                        break;

                }
                input = Console.ReadLine();
            }

            foreach (int taskHour in tasksHours)

            {
                if (taskHour > 0)

                {

                    Console.Write(taskHour+" ");
                }

               
            }
           
        }
    }
}

), но ми дава RunTime error в Judge,съответно на тест 2,4 и 6 и получавам 70/100. Много ще съм ви благодарна за някакви насоки!

Поздрави.

Дени

Tasks Planner

 

Create a program that helps you organize your daily tasks. First, you are going to receive the hours each task takes оn a single line, separated by space, in the following format:

"{task1} {task2} {task3}… {taskn}"

Each task takes from 1 to 5 hours. If its time is set to 0 – it is completed. If its time is set to a negative number – the task is dropped.

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

  • "Complete {index}"
    • Find the task on this index in your collection and complete it, if the index exists.
  • "Change {index} {time}"
    • Replace the time needed of the task on the given index with the time given, if the index exists.
  • "Drop {index}"
    • Drop the task on the given index, setting its hour to -1, if the index exists.
  • "Count Completed"
    • Print the number of completed tasks.
  • "Count Incomplete"
    • Print the number of incomplete tasks (this doesn’t include the dropped tasks).
  • "Count Dropped"
    • Print the number of dropped tasks (this doesn’t include the incomplete tasks).

In the end, print the incomplete tasks on a single line, separated by a single space in the following format:

"{task1} {task2} {task3}… {taskn}"

Input

  • On the 1st line you are going to receive the time of each task, 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.

 

 

Examples

Input

Output

1 -1 2 3 4 5
Complete 4
Change 0 4
Drop 3

Count Dropped
End

2
4 2 5

Comments

First, we receive the command "Complete 4" and we to complete the task on index 4. After this command, the task collection looks like this:

1 -1 2 3 0 5

Afterwards, we receive the "Change 0 4" command and we need to change the time of the task on index 0. The collection looks like this now:

4 -1 2 3 0 5

After, we receive the "Drop 3" command, which means we need to drop the task on index 3. The collection looks like this:

4 -1 2 -1 0 5

Then, we receive the "Count Dropped" command. The result is 2 as we have only 2 dropped tasks.

In the end, we print all of the incomplete tasks. This is the result collection:

4 2 5

 

 

1 2 3 4 5 4 0 3 2 1
Complete 0
Complete 1
Complete 2
Drop 3
Change 4 1

Count Completed
End

4
1 4 3 2 1

 

Тагове:
0
Module: C# Advanced 30/01/2020 14:47:19
Denislava91 avatar Denislava91 5 Точки

BasedGod, много благодаря за кода.

Разгледах го, промених някои неща при мен, но си мисля, че логиката ни е една и съща и просто не мога да разбера защо ми дава Run time error. Единствената съществена разлика е, че ти си използвал if; else if, а аз switch. Но за мен това не би трябвало да е причина да ми дава 70/100. Много ще съм благодарна, ако дадеш/ някой даде някаква идея какво му е грешно на моя код: https://pastebin.com/zKRpnWYP.

 

Предварително благодаря.

Поздрави.

 

Дени

0
BasedGod avatar BasedGod 1 Точки

Намерих ти грешката, при проверка за индекса if (index >= 0 || index < tasksHours.Length) ти използваш оператора ||(ИЛИ), промених ги на &&(И) така дава 100 точки, отнася се за всички проверки.

 

0
Denislava91 avatar Denislava91 5 Точки

BasedGod,

Изобщо не съм го видяла:)

Много ти благодаря.

Поздрави.

Дени

0
kalina_ilieva avatar kalina_ilieva 4 Точки

Здравей,

разгледах старите решения и го сравнявам с моят код, но не успявам да си намери грешката. Моля, за помощ.

Дава ми 90/100.

https://pastebin.com/KFkL0Kjp

 

Благодаря предварително,

Калина

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