Skip to content

Instantly share code, notes, and snippets.

@HairyFotr
Forked from edofic/naloga6.ugly.scala
Last active December 11, 2015 08:49
Show Gist options
  • Save HairyFotr/4576063 to your computer and use it in GitHub Desktop.
Save HairyFotr/4576063 to your computer and use it in GitHub Desktop.
import collection.mutable._;object A{type S=String;def main(a:Array[S]){val s=a(0);val p=a.size==2;val e=if(p)a(1)else s.sorted;val c=new java.util.Scanner(System.in);while(c.hasNextLine){val w=c.nextLine;i(new N(w,if(p)w==e else w.sorted==e&&w!=s))};val q=Queue[N]();val k=y(s);k.c=0;def x(z:N){if(z.t)return;if(!z.v){z.e.map{e=>if(e.c>z.c+1)e.p.clear;if(e.c>z.c){e.c=z.c+1;e.p.append(z)};if(!e.v)q.enqueue(e)}};z.v=true;if(q.size>0)x(q.dequeue)};x(k);for{n<-y.values if(n.p.size>0&&n.t)}n.P("")};val y=Map[S,N]();def i(n:N)=for(m<-y.values;if(d(m.k,n.k)==1)){m.e.append(n);n.e.append(m)};def d(r:S,s:S)=r.zip(s).filter{t=>t._1!=t._2}.size;class N(val k:S,val t:Boolean){val e,p=ListBuffer[N]();var c=2147483647;var v=false;def P(a:S){if(p.isEmpty)println(k+a)else p.map(_.P("->"+k+a))}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment