#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.
on line 46 remove the space after %ld and it evaluates 100%
ReplyDeletecan someone send the answer in c++
ReplyDelete#include
ReplyDelete#include
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 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("Ordered List\n");
for(i=0;i<b;i++) {
printf("%s %ld\n",s1[i].c,s1[i].a);
}
if(lol!=0) {
printf("\nName Telephone Number\n%s %ld",ans,an);}
else {
printf("\nName Telephone Number\nThe Entered Number is not in the Directory"); }
return 0;
}