Type the Question

Saturday, February 16, 2019

Question Name:Sorted Student List

#include <stdio.h>
#include<string.h>
struct aviraj 
{ 
  int a;
  char c[50];
} s1[20];
int main()
{
int l,i,j,tep;
  char temp [50];
  scanf("%d",&l);
  for(i=0;i<l;i++) { 
    scanf("%s %d",s1[i].c,&s1[i].a); 
  }
  for (i = 0; i < l - 1 ; i++)
{
for (j = i + 1; j < l; j++)
{
if (strcmp(s1[i].c, s1[j].c) > 0)
{
strcpy(temp, s1[i].c); tep=s1[i].a;

strcpy(s1[i].c, s1[j].c); s1[i].a=s1[j].a;
strcpy(s1[j].c, temp); s1[j].a=tep;
}
}
  }
  printf("After sorting\nName ID\n");
   for(i=0;i<l;i++) { 
   printf("%s %d\n",s1[i].c,s1[i].a); 
   }
 return 0;
}

Problem Description

In CSE Department, there are 10 students, where students list was in the enrollment order. You have to prepare list students in the alphabetical order.
  • Test Case 1
    Input (stdin)
    10
    Anu 87
    Rahul 95
    Atul 21
    Ram 101
    Rithwik 45
    saleem 55
    Amit 88
    Jancy 66
    Jibin 65
    Ashwin 75
    Expected Output
    After sorting
    Name ID
    Amit 88
    Anu 87
    Ashwin 75
    Atul 21
    Jancy 66
    Jibin 65
    Rahul 95
    Ram 101
    Rithwik 45
    saleem 55
  • Test Case 2
    Input (stdin)
    8
    Atul 21
    Ram 101
    Rithwik 45
    saleem 55
    Amit 88
    Jancy 66
    Jibin 65
    Ashwin 75
    Expected Output
    After sorting
    Name ID
    Amit 88
    Ashwin 75
    Atul 21
    Jancy 66
    Jibin 65
    Ram 101
    Rithwik 45
    saleem 55

No comments:

Post a Comment

Question Name:TOWER OF HANOI

#include < bits / stdc ++. h > #define lli long long using namespace std ; lli dp [ 202 ]; int main () { int t , n ; ...