#include <stdio.h> #include <string.h> struct avi { char c[50]; int a; } s1[20]; int main() { int i,k,tem,j,max=0,max1=0,v; char temp[50]; k=10; for(i=0;i<k;i++) { scanf("%s%d",s1[i].c,&s1[i].a); } for(i=0;i<k;i++) { if(max<s1[i].a) { max=s1[i].a;} } for(i=0;i<k;i++) { if(max1<s1[i].a && s1[i].a!=max) { max1=s1[i].a;} } for(i=0;i<k;i++) { for(j=i+1;j<k;j++) { if(s1[i].a<s1[j].a) { tem=s1[i].a; strcpy(temp, s1[i].c); s1[i].a=s1[j].a; strcpy(s1[i].c, s1[j].c); s1[j].a=tem; strcpy(s1[j].c, temp); } } } if(s1[4].a==s1[5].a){ strcpy(temp, s1[4].c); strcpy(s1[4].c, s1[5].c); strcpy(s1[5].c, temp); } printf("Ordered List\n"); for(i=0;i<k;i++) { printf("%s",s1[i].c); for(v=strlen(s1[i].c);v<8;v++) { printf(" ");} printf("%d\n" ,s1[i].a) ; } //if(s1[4].a==s1[5].a){ // printf("\nName Year\n%s %d",s1[5].c,s1[5].a); //} // else // { printf("\nSecond Highest mark is %d",max1); // } return 0; }
Problem Description
The DS teacher wants to know the student of second highest mark in CT 1, if she has a ordered list of marks for 10 students.
-
Test Case 1
Input (stdin)
Thomas 75 Imran 60 Sithik 55 Setan 80 Milton 85 Arjun 90 Rakesh 91 Hrithik 88 Ayush 72 Aswathy 96
Expected Output
Ordered List Aswathy 96 Rakesh 91 Arjun 90 Hrithik 88 Milton 85 Setan 80 Thomas 75 Ayush 72 Imran 60 Sithik 55 Second Highest mark is 91
-
Test Case 2
Input (stdin)
Thomas 75 Imran 60 Sithik 10 Setan 80 Milton 85 Arjun 90 Rakesh 91 Hrithik 88 Ayush 72 Aswathy 55
Expected Output
Ordered List Rakesh 91 Arjun 90 Hrithik 88 Milton 85 Setan 80 Thomas 75 Ayush 72 Imran 60 Aswathy 55 Sithik 10 Second Highest mark is 90