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?
Здравей,
твоето решение дава 70/100.
направи една double променлива извън цикъла за изчисляване на процента, например - double percent = (double)power * 0.50. В if проверката постави нея и ще ти върне 100/100
пример - if (power == percent && factor != 0)
Извинявай, в бързината не съм извел процента. В случая, както ти бях дал първото решение, процента на първоначалната сила на покемон-а спада при всяко завъртане на цикъла и затова трябва да е извън тялото на цикъла. Сорри
Благодаря ,
така е ок - 100/100