Question Name:Student Name 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

If you are class teacher, you have some number of students in your class. You have to prepare the namelist for attendance in the alphabetical order.

  • Test Case 1

    Input (stdin)

    15
    Ram 101
    Rahul 95
    Ashwin 75
    saleem 55
    Rithwik 45
    Anu 87
    Amit 88
    Jancy 66
    Atul 21
    Jibin 65
    Jithin 22
    Stebin 10
    Harika 28
    Mancy 25
    Avinash 78
    

    Expected Output

    After sorting
    Name ID
    Amit 88
    Anu 87
    Ashwin 75
    Atul 21
    Avinash 78
    Harika 28
    Jancy 66
    Jibin 65
    Jithin 22
    Mancy 25
    Rahul 95
    Ram 101
    Rithwik 45
    Stebin 10
    saleem 55
  • Test Case 2

    Input (stdin)

    10
    Ram 101
    Rahul 95
    Ashwin 75
    saleem 55
    Rithwik 45
    Anu 87
    Amit 88
    Jancy 66
    Atul 21
    Jibin 65
    

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro