📜  第 N 天结束时未解决的问题

📅  最后修改于: 2021-10-25 06:24:53             🧑  作者: Mango

给定 3 个整数 K、P 和 N。其中,K 是该人每天解决的问题数,P 是他一天可以解决的最大问题数。求第 N 天后未解决的问题总数。
例子

Input :  K = 2, P = 1, N = 3
Output : 3
On each day 1 problem is left so 3*1 = 3 
problems left after Nth day.

Input : K = 4, P = 1, N = 10
Output : 30

如果 P 大于或等于 K,那么当天所有问题都将得到解决,或者 (KP) 个问题将在每一天解决,因此如果 K<=P,则答案为 0,否则答案为 (KP)*N .
下面是上述方法的实现:

C++
// C++ program to find problems not
// solved at the end of Nth day
 
#include 
using namespace std;
 
// Function to find problems not
// solved at the end of Nth day
int problemsLeft(int K, int P, int N)
{
    if (K <= P)
        return 0;
    else
        return (K - P) * N;
}
 
// Driver Code
int main()
{
    int K, P, N;
 
    K = 4;
    P = 1;
    N = 10;
 
    cout << problemsLeft(K, P, N);
 
    return 0;
}


Java
// Java program to find problems not
// solved at the end of Nth day
 
class Gfg {
 
    // Function to find problems not
    // solved at the end of Nth day
    public static int problemsLeft(int K, int P, int N)
    {
        if (K <= P)
            return 0;
        else
            return ((K - P) * N);
    }
 
    // Driver Code
    public static void main(String args[])
    {
        int K, P, N;
        K = 4;
        P = 1;
        N = 10;
 
        System.out.println(problemsLeft(K, P, N));
    }
}


Python3
# Python program to find problems not
# solved at the end of Nth day
 
def problemsLeft(K, P, N):
    if(K<= P):
        return 0
    else:
        return ((K-P)*N)
 
# Driver Code
K, P, N = 4, 1, 10
 
print(problemsLeft(K, P, N))


C#
// C# program to find problems not
// solved at the end of Nth day
using System;
 
class GFG
{
 
// Function to find problems not
// solved at the end of Nth day
public static int problemsLeft(int K,
                               int P, int N)
{
    if (K <= P)
        return 0;
    else
        return ((K - P) * N);
}
 
// Driver Code
public static void Main()
{
    int K, P, N;
    K = 4;
    P = 1;
    N = 10;
 
    Console.WriteLine(problemsLeft(K, P, N));
}
}
 
// This code is contributed by vt_m


PHP


Javascript


输出:
30

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程