📜  查找是否可以休假

📅  最后修改于: 2021-04-21 21:02:58             🧑  作者: Mango

给出以下值:

  • N是剩余的考试天数。
  • S是要准备考试的科目数。
  • C是为每个主题准备的章节数。
  • H是准备一章的小时数。
  • L是所需假期的天数。在这个假期期间,无法完成学习。
  • T是一天中可以学习的小时数。

任务是查找是否可以进行所需的假期。如果可以获取,则打印“是” ,否则打印“否”

例子:

方法:

  1. 通过乘以SCH来找到所需的学习小时数
  2. 现在找到如果休假可以完成的学习时间。这些小时数等于我们剩下的剩余天数乘以T小时数(即(NL)* T)。
  3. 现在检查所需时间是否少于或等于休假时可以完成的学习时间。如果为true,则打印“是” ,否则打印“否”

    下面是上述方法的实现:

    C++
    // C++ program to find
    // if the Vacation can be taken or not
      
    #include 
    using namespace std;
      
    // Function to find if the Vacation
    // is possible or not
    int isPossible(int N, int S, int C, int H,
                   int L, int T)
    {
      
        // Find the required number of hours of study
        int total_time_required = S * C * H;
      
        // find the hours of study that can be done
        // if the vacation is taken
        int available_time_after_vacation = (N - L) * T;
      
        // check if the required hours are less than
        // or equal to the hours of study
        // that can be done if the vacation is taken
        if (available_time_after_vacation
            >= total_time_required)
            return 1;
        return 0;
    }
      
    // Driver Code
    int main()
    {
        int N = 12, S = 5, C = 8,
            H = 3, L = 2, T = 20;
      
        if (isPossible(N, S, C, H, L, T))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
      
        N = 1, S = 2, C = 3,
        H = 4, L = 5, T = 6;
      
        if (isPossible(N, S, C, H, L, T))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
      
        return 0;
    }


    Java
    // Java program to find
    // if the Vacation can be taken or not
    class GFG
    {
      
    // Function to find if the Vacation
    // is possible or not
    static int isPossible(int N, int S, int C, int H,
                           int L, int T)
    {
      
        // Find the required number of hours of study
        int total_time_required = S * C * H;
      
        // find the hours of study that can be done
        // if the vacation is taken
        int available_time_after_vacation = (N - L) * T;
      
        // check if the required hours are less than
        // or equal to the hours of study
        // that can be done if the vacation is taken
        if (available_time_after_vacation
            >= total_time_required)
            return 1;
        return 0;
    }
      
    // Driver Code
    public static void main(String[] args)
    {
        int N = 12, S = 5, C = 8,
            H = 3, L = 2, T = 20;
      
        if (isPossible(N, S, C, H, L, T) == 1)
            System.out.print("Yes" + "\n");
        else
            System.out.print("No" + "\n");
      
        N = 1; S = 2; C = 3;
        H = 4; L = 5; T = 6;
      
        if (isPossible(N, S, C, H, L, T)==1)
            System.out.print("Yes" + "\n");
        else
            System.out.print("No" + "\n");
    }
    }
      
    // This code is contributed by 29AjayKumar


    Python3
    # Python3 program to find
    # if the Vacation can be taken or not
      
    # Function to find if the Vacation
    # is possible or not
    def isPossible(N, S, C, H, L, T):
          
        # Find the required number of hours of study
        total_time_required = S * C * H
          
        # find the hours of study that can be done
        # if the vacation is taken
        available_time_after_vacation = (N - L) * T
          
        # check if the required hours are less than
        # or equal to the hours of study
        # that can be done if the vacation is taken
        if (available_time_after_vacation >= total_time_required):
            return 1
        return 0
      
    # Driver Code
    N = 12
    S = 5
    C = 8
    H = 3
    L = 2
    T = 20
      
    if (isPossible(N, S, C, H, L, T)):
        print("Yes")
    else:
        print("No")
      
    N = 1
    S = 2
    C = 3
    H = 4
    L = 5
    T = 6
      
    if (isPossible(N, S, C, H, L, T)):
        print("Yes")
    else:
        print("No")
              
    # This code is contributed by SHUBHAMSINGH10


    C#
    // C# program to find
    // if the Vacation can be taken or not
    using System;
      
    class GFG
    {
      
    // Function to find if the Vacation
    // is possible or not
    static int isPossible(int N, int S, int C, int H,
                        int L, int T)
    {
      
        // Find the required number of hours of study
        int total_time_required = S * C * H;
      
        // find the hours of study that can be done
        // if the vacation is taken
        int available_time_after_vacation = (N - L) * T;
      
        // check if the required hours are less than
        // or equal to the hours of study
        // that can be done if the vacation is taken
        if (available_time_after_vacation
            >= total_time_required)
            return 1;
        return 0;
    }
      
    // Driver Code
    public static void Main(String[] args)
    {
        int N = 12, S = 5, C = 8,
            H = 3, L = 2, T = 20;
      
        if (isPossible(N, S, C, H, L, T) == 1)
            Console.Write("Yes" + "\n");
        else
            Console.Write("No" + "\n");
      
        N = 1; S = 2; C = 3;
        H = 4; L = 5; T = 6;
      
        if (isPossible(N, S, C, H, L, T)==1)
            Console.Write("Yes" + "\n");
        else
            Console.Write("No" + "\n");
    }
    }
      
    // This code is contributed by 29AjayKumar


    输出:
    Yes
    No