Loading...

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

Stanislav_Stoyanov avatar Stanislav_Stoyanov 0 Точки

10. *Poke Mon

A Poke Mon is a special type of pokemon which likes to Poke others. But at the end of the day, the Poke Mon wants
to keeps statistics, about how many pokes it has managed to make.
The Poke Mon pokes his target, and then proceeds to poke another target. The distance between his targets
reduces his poke power.
You will be given the poke power the Poke Mon has, N – an integer.
Then you will be given the distance between the poke targets, M – an integer.
Then you will be given the exhaustionFactor Y – an integer.

Your task is to start subtracting M from N until N becomes less than M, i.e. the Poke Mon does
not have enough power to reach the next target.
Every time you subtract M from N that means you’ve reached a target and poked it
successfully. COUNT how many targets you’ve poked – you’ll need that count.
The Poke Mon becomes gradually more exhausted. IF N becomes equal to EXACTLY 50 % of its
original value, you must divide N by Y, if it is POSSIBLE. This DIVISION is between integers.
If a division is not possible, you should NOT do it. Instead, you should continue subtracting.

Page 1 of 9 Follow us:
© Software University Foundation. This work is licensed under the CC-BY-NC-SA license.

After dividing, you should continue subtracting from N, until it becomes less than M.
When N becomes less than M, you must take what has remained of N and the count of targets you’ve poked, and
print them as output.

NOTE: When you are calculating percentages, you should be PRECISE at maximum.
Example: 505 is NOT EXACTLY 50 % from 1000, its 50.5 %.
Input
 The input consists of 3 lines.
 On the first line you will receive N – an integer.
 On the second line you will receive M – an integer.
 On the third line you will receive Y – an integer.
Output
 The output consists of 2 lines.
 On the first line print what has remained of N, after subtracting from it.
 On the second line print the count of targets, you’ve managed to poke.
Constrains
 The integer N will be in the range [1, 2.000.000.000].
 The integer M will be in the range [1, 1.000.000].
 The integer Y will be in the range [0, 9].
 Allowed time / memory: 16 MB / 100ms.

 

using System;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)


        {
            int power = int.Parse(Console.ReadLine());
            int distance = int.Parse(Console.ReadLine());
            int factor = int.Parse(Console.ReadLine());
            int counter = 0;

            if (power < distance)
            {
                Console.WriteLine(power);
                Console.WriteLine(counter);
            }
            else
            {
                while (power >= distance)
                {
                    if (power - distance == power * 0.5 && factor > 0)
                    { 
                        power = (power - distance) / factor;
                    }
                    else
                    {
                        power -= distance;
                    }
                    counter++;
                }
                Console.WriteLine(power);
                Console.WriteLine(counter);

            }

        }
    }
}

 

Здравейте, може ли малко помощ - защо получавам 80/100?

Тагове:
0
Module: C# Advanced
kkaraivanov avatar kkaraivanov 486 Точки

Здравей, и аз много се мъчих над това решение и в крайна сметка проблема се окаа на проверката където добавих проверка "Y != 0".

Редактирах малко решението ти, но би трябвало да ти даде 100/100:

static void Main(string[] args)
{
   int power = int.Parse(Console.ReadLine());
   int distance = int.Parse(Console.ReadLine());
   int factor = int.Parse(Console.ReadLine());
   int counter = 0;

   while (power >= distance)
   {
       counter++;
       power -= distance;
       if ((power == (double)power * 0.50) && factor != 0)
       {
           power /= factor;
       }
    }
    Console.WriteLine(power);
    Console.WriteLine(counter);
}

 

0
Stanislav_Stoyanov avatar Stanislav_Stoyanov 0 Точки

Здравей, 

твоето решение дава 70/100.

 

0
kkaraivanov avatar kkaraivanov 486 Точки

направи една double променлива извън цикъла за изчисляване на процента, например - double percent = (double)power * 0.50. В if проверката постави нея и ще ти върне 100/100

пример - if (power == percent && factor != 0)

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

0
18/01/2020 17:43:33
Stanislav_Stoyanov avatar Stanislav_Stoyanov 0 Точки

Благодаря , 

 

така е ок - 100/100

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