PKU 1750 Dictionary

http://poj.org/problem?id=1750
ルールに従って与えられた単語から辞書を作れというような問題。

サンプルを見てなんとなく規則性を見つけました。
入出力を多少高速化しないとTLEしました。

char*be;
char*th;
char in[2][100];

main(){
  gets(in[0]);
  be=in[0];
  puts(be);
  int sp=0;
  int ti=0;
  while(gets(in[++ti%2])){
    int tsp=sp+1;
    th=in[ti%2];
    rep(i,sp+1){
      if(!be[i] || !th[i] || be[i]!=th[i]){
        tsp=i;
        break;
      }
    }
    rep(i,tsp)putchar(' ');
    puts(th);
    sp=tsp;
    be=th;
  }
}