Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.50 KB | None | 0 0
  1. #! /usr/bin/gawk -f
  2. BEGIN{
  3.     while((getline < "/home/adav/cities")==1){
  4.     a[len++]=$0;print len,$0
  5.     }
  6.     close("/home/adav/cities");
  7.     max=0;
  8. }
  9.  
  10. function try(i,       s,lvl,j,found){
  11.    b[i]=1;
  12.     found=0;
  13.     for(j=0;j<len;j++){
  14.     if((substr(a[i],length(a[i]),1)==substr(a[j],1,1))&&
  15.        !b[j]){
  16.         found=1;
  17.         try(j,s ", " a[i],lvl+1);
  18.     }
  19.     }
  20.   b[i]=0;
  21.   if(!found)if((lvl>=max)) {max=lvl;
  22.       print lvl+1, s ", " a[i];
  23.       }
  24. }
  25. END{
  26.     for(z=0;z<len;z++)try(z,"",0);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement