原文:
给定 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,那么所有问题将在当天解决,或者(k-p)问题将在每天解决,因此如果 k <=p else the answer will be (k-p)*n. 答案将为 0。以下是上述方法的实现:
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));
}
}
python 3
# 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
服务器端编程语言(professional hypertext preprocessor 的缩写)
java 描述语言
output:
30
麻将胡了pg电子网站的版权属于:月萌api www.moonapi.com,转载请注明出处