Question Name:Telephone

#include <stdio.h>
#include <string.h>

struct avi
{
char c[10];
long a;
} s1[20];
int main(){

long an,q,tep;
int b,i,p=10,j,lol=0;
char s[10],c[10],temp[50],ans[50];
scanf("%d",&b);
for(i=0;i<b;i++) {
scanf("%s %ld",s1[i].c,&s1[i].a);

//strcpy(c,s);
}
scanf("%ld",&q);
for(i=0;i<b;i++)
{
if(s1[i].a==q) {
an=s1[i].a;
strcpy(ans,s1[i].c);lol++;
}
}

for (i = 0; i < b - 1 ; i++)
{
for (j = i + 1; j < b; 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;
}
}
}
//this code is not evaluatingg even when answer is correct there is some problem in output spacing
printf("Ordered List");
for(i=0;i<b;i++) {

printf("\n%s %ld ",s1[i].c,s1[i].a);
}
if(lol!=0) {
printf("\n\nName Telephone Number\n%s %ld",ans,an);}
else {
printf("\n\nName Telephone Number\nThe Entered Number is not in the Directory"); }
return 0;
}


Problem Description

You Have to find the name of the person having phone number “XXXXXXXXXX” in the telephone directory. Since the telephone directory is in alphabetical order not by numbers, you have to go through each and every name of the telephone directory.
    • Test Case 1
      Input (stdin)
      10
      Rahul 9598454222
      Ashwin 7501202255
      saleem 8545222522
      Rithwik 7853266523
      Anu 8832266636
      Jancy 7852366336
      Atul 7515555655
      Jibin 9852453662
      Jithin 7855656332
      Stebin 8762556625
      
      9598454222
      Expected Output
      Ordered List
      Anu 8832266636
      Ashwin 7501202255
      Atul 7515555655
      Jancy 7852366336
      Jibin 9852453662
      Jithin 7855656332
      Rahul 9598454222
      Rithwik 7853266523
      Stebin 8762556625
      saleem 8545222522
      
      Name Telephone Number
      Rahul 9598454222
    • Test Case 2
      Input (stdin)
      5
      Rahul 9598454222
      Anu 8832266636
      Jancy 7852366336
      Atul 7515555655
      Jibin 9852453662
      Stebin 8762556625
      
      9598454222
      Expected Output
      Ordered List
      Anu 8832266636
      Atul 7515555655
      Jancy 7852366336
      Jibin 9852453662
      Rahul 9598454222
      
      Name Telephone Number
      The Entered Number is not in the Directory

    Comments

    Popular Posts