#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 - 1 ; i++)
{
for (j = i + 1; j < k; j++)
{
if (strcmp(s1[i].c, s1[j].c) > 0)
{
strcpy(temp, s1[i].c); tem=s1[i].a;
strcpy(s1[i].c, s1[j].c); s1[i].a=s1[j].a;
strcpy(s1[j].c, temp); s1[j].a=tem;
}
}
}
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"); printf("Name ID\n");
for(i=0;i<k;i++) {
printf("%s %d\n",s1[i].c,s1[i].a);
}
return 0;
}
Problem Description
You are given a word document in that there will be list of employees name will be unordered, you have to arrange the list of employee in the alphabetical order in the word document.
Test Case 1
Input (stdin)
10
Thomas 20
Imran 21
Sithik 22
Setan 27
Milton 30
Arjun 16
Rakesh 26
Hrithik 65
Ayush 54
Aswathy 29
Expected Output
After sorting
Name ID
Arjun 16
Aswathy 29
Ayush 54
Hrithik 65
Imran 21
Milton 30
Rakesh 26
Setan 27
Sithik 22
Thomas 20
Test Case 2
Input (stdin)
6
Thomas 26
Sithik 32
Milton 45
Hrithik 60
Ayush 52
Aswathy 22
Expected Output
After sorting
Name ID
Aswathy 22
Ayush 52
Hrithik 60
Milton 45
Sithik 32
Thomas 26
No comments:
Post a Comment