C++ || STL || standard template libraries

Image
                                       C++ STL  1.      Pair :  Syntax :      pair <int,char> p1;     it creates a pair {2,'c'} like this.           pair <int,int> p2;     it creates a pair {2,3} like this .  Basic Code :  #include <bits/stdc++.h> using namespace std; int main() {     // cout<<"hello world\n";     pair <int,int> p1 = {1,2};     cout<<p1.first<< " "<< p1.second<<endl;          pair <int, pair<int ,char>> p2 = {1,{2,'c'}};     cout<<p2.first<<" "<<p2.second.first<<" "<<p2.second.second<<endl;          pair <int,int> arr[] = {{2,3},{4,5},{6,7}};     cout...

Find the second lowest grade in the nested list:

Given the names and grades for each student in a class of  students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.


Hacker Rank Solution:  

 if __name__ == '__main__':

    student_list = []
    for _ in range(int(input())):
        name = input()
        score = float(input())
        student_list.append([name,score])
    # print(student_list)    
    
scores_list = sorted(list(set([student[1] for student in student_list])))
# print(scores_list)
second_lowest_grade = scores_list[1]
student_second_lowest_grade = [
    student[0] 
    for student in student_list
    if(student[1]==second_lowest_grade)


]
student_second_lowest_grade.sort()
for i in student_second_lowest_grade:
    print(i)

Comments

Popular posts from this blog

1050. Actors and Directors Who Cooperated At Least Three Times || Leetcode sql solution || Simple and Easy Approach || ✅✅✅✅💯💯💯🔥🔥🔥🔥

Power of Millets || Happy And Healthy Life

c program to clear nth bit of the number || Bitwise Operators || Problem Solving ||