📌  相关文章
📜  最初查找男性人数的程序

📅  最后修改于: 2021-04-22 05:55:23             🧑  作者: Mango

一定数量的男人可以在D天里完成某些工作。如果有m以下的人从事的工作,然后工作可以在d天少做。任务是找到最初有多少人。
例子:

方法:让男人的初始人数为M ,天数为D
D天内完成的M个工作的工作量为M * D
完成的工作= M * D …(1)
如果有M + m人,则在D – d天完成相同的工作量。
完成的工作=(M + m)*(D – d) …(2)
等式1和2

下面是上述方法的实现:

C++
// C++ implementation of above approach.
#include 
using namespace std;
 
// Function to return the
// number of men initially
int numberOfMen(int D, int m, int d)
{
 
    int Men = (m * (D - d)) / d;
 
    return Men;
}
 
// Driver code
int main()
{
    int D = 5, m = 4, d = 4;
 
    cout << numberOfMen(D, m, d);
 
    return 0;
}


Java
// Java implementation of the approach
import java.util.*;
 
class GFG
{
     
// Function to return the
// number of men initially
static int numberOfMen(int D, int m, int d)
{
 
    int Men = (m * (D - d)) / d;
 
    return Men;
}
 
// Driver code
public static void main(String args[])
{
    int D = 5, m = 4, d = 4;
 
    System.out.println(numberOfMen(D, m, d));
 
}
}
// This code is contributed by Arnab Kundu


Python3
# Python implementation of above approach.
 
# Function to return the
# number of men initially
def numberOfMen(D, m, d):
    Men = (m * (D - d)) / d;
 
    return int(Men);
 
 
# Driver code
D = 5; m = 4; d = 4;
 
print(numberOfMen(D, m, d));
 
 
# This code contributed by Rajput-Ji


C#
//  C# implementation of the approach
using System;
 
class GFG
{
     
// Function to return the
// number of men initially
static int numberOfMen(int D, int m, int d)
{
 
    int Men = (m * (D - d)) / d;
 
    return Men;
}
 
// Driver code
public static void Main()
{
    int D = 5, m = 4, d = 4;
 
    Console.WriteLine(numberOfMen(D, m, d));
 
}
}
 
// This code is contributed by anuj_67..


Javascript


输出:
1