给定最后的排名“ L”和最后一个排名“ T”的候选人数量,任务是查找考试中的候选人总数。
Input: L = 5, T = 1
Output: 5
Input: L = 10, T = 2
Output: 11
方法:
- 假设L = 5且T = 2。
- 然后可以有许多可能的等级组合,例如1、2、3、3、5、5。
- 因此,现在您可以看到,最后的排名是5,而2名学生排名5,
- 因此,候选人总数= 6。
- 这可以通过一个简单的公式来理解:
L+T-1
以下是上述方法的实现。
C++
// C++ program to find total number of candidates
// in an Exam from given last rank
// and Number of student at this last rank.
#include
using namespace std;
// Function to find total number of
// Participants in Exam.
int findParticipants(int L, int T)
{
return (L + T - 1);
}
// Driver code
int main()
{
int L = 10, T = 2;
cout << findParticipants(L, T);
return 0;
}
Java
// Java program to find total number of
// candidates in an Exam from given last rank
// and Number of student at this last rank.
class GFG
{
// Function to find total number of
// Participants in Exam.
static int findParticipants(int L, int T)
{
return (L + T - 1);
}
// Driver code
public static void main(String args[])
{
int L = 10, T = 2;
System.out.print(findParticipants(L, T));
}
}
// This code is contributed by Gowtham Yuvaraj
Python3
# Python3 program to find total number
# of candidates in an Exam from given last rank
# and Number of student at this last rank.
# Function to find total number of
# Participants in Exam.
def findParticipants(L, T) :
return (L + T - 1);
# Driver code
if __name__ == "__main__" :
L = 10; T = 2;
print(findParticipants(L, T));
# This code is contributed by AnkitRai01
C#
// C# program to find total number of
// candidates in an Exam from given last rank
// and Number of student at this last rank.
using System;
class GFG
{
// Function to find total number of
// Participants in Exam.
static int findParticipants(int L, int T)
{
return (L + T - 1);
}
// Driver code
public static void Main()
{
int L = 10, T = 2;
Console.Write(findParticipants(L, T));
}
}
// This code is contributed by Gowtham Yuvaraj
输出:
11
想要从精选的最佳视频中学习并解决问题,请查看有关从基础到高级C++的C++基础课程以及有关语言和STL的C++ STL课程。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。