#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; }
Thursday, January 9, 2020
Telephone
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment