#include <stdio.h>
#include <string.h>
struct avi
{
char c[50];
int a;
} s1[20];
int main()
{
int i,k,tem,j;
char temp[50];
scanf("%d",&k);
for(i=0;i<k;i++) {
scanf("%s%d",s1[i].c,&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[6].a==s1[5].a) {
tem=s1[6].a; strcpy(temp, s1[6].c);
s1[6].a=s1[5].a; strcpy(s1[6].c, s1[5].c);
s1[5].a=tem; strcpy(s1[5].c, temp);
}
printf("After sorting\n");
for(i=0;i<k;i++) {
printf("%s %d\n",s1[i].c,s1[i].a);
}
return 0;
}
Problem Description
In the company, there are some number of employees. Employee list was unordered. You have to prepare the list of the employee details depending upon year of entry.
Test Case 1
Input (stdin)
5
Thomas 2000
Imran 2002
Sithik 2001
Setan 2004
Milton 2007
Expected Output
After sorting
Thomas 2000
Sithik 2001
Imran 2002
Setan 2004
Milton 2007
Test Case 2
Input (stdin)
10
Thomas 2000
Imran 2002
Sithik 2001
Setan 2004
Milton 2007
Arjun 1997
Rakesh 2004
Hrithik 2008
Ayush 2009
Aswathy 2003
Expected Output
After sorting
Arjun 1997
Thomas 2000
Sithik 2001
Imran 2002
Aswathy 2003
Setan 2004
Rakesh 2004
Milton 2007
Hrithik 2008
Ayush 2009
No comments:
Post a Comment