Wednesday 22 June 2016

Help via.com to find the route map which had been lost by them..

#include<stdio.h>
#include<string.h>
char s[10][100],d[10][100],sr[100],flag=0;
int n,city=0,j=0,count=0;
int find(char *so){
for(j=0;j<n;j++){
flag=0;
if(strcmp(so,s[j])==0){
count++;
flag=1;
find(d[j]);
}
if(j==(n-1) && flag==0 ){
break;
}
}
return count;
}
void route(char *source){
for(j=0;j<n;j++){
if((strcmp(source,s[j])==0)){
printf("->%s",d[j]);
route(d[j]);
}
}
}
int main(){
int i,k;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s%s",s[i],d[i]);
}
for(i=0;i<n;i++){
city=find(s[i]);
if(city==n){
printf("route is %s",s[i]);
route(s[i]);
}
else{
count=0;
}
}
return 0;
}

}

No comments:

Post a Comment