pku + 1760

  1 #include <iostream>
  2 #include <vector>
  3 #include <string>
  4 #include <new>
  5 #include <algorithm>
  6 using namespace std;
  7 
  8 struct nod;
  9 
 10 struct nod1 {
 11     vector<nod *> wen_jian;
 12 };
 13 
 14 struct nod {
 15     int num;
 16     string word;
 17     nod1 *next;
 18 };
 19 
 20 nod1 *head = new nod1;
 21 
 22 void zhuan( string &str1 )
 23 {
 24     nod1 *p_rear = head;
 25     string str_word;
 26     string ::iterator p = str1.begin(),q = str1.end();
 27     int n = 0;
 28     while ( p != q )
 29     {
 30         str_word = "";
 31         while ( 1 )
 32         {
 33             str_word += *p++;
 34             if ( p == q  )
 35                 break;
 36             if ( *== '\\' )
 37             {
 38                 ++p;
 39                 break;
 40             }
 41         }
 42         bool y = false;
 43         for ( vector<nod *>::iterator p_nod1 = p_rear->wen_jian.begin(),q_nod1 = p_rear->wen_jian.end();p_nod1 != q_nod1; ++p_nod1 )
 44         {
 45             if ( (*p_nod1)->word == str_word  )
 46             {
 47                 p_rear = (*p_nod1)->next;
 48                 y = true;
 49                 break;
 50             }
 51         }
 52         if ( y == false )
 53         {
 54             nod *p_nod = new nod; // 建¨一?个? nod 类え?型í
 55             p_nod ->num = n; // 表括?示?层?数簓
 56             p_nod ->word = str_word; // 表括?示?此?单蹋?词洙?
 57             p_nod ->next = new nod1; //开a放?新?的?层?数簓
 58             p_rear->wen_jian.push_back(p_nod);
 59             p_rear = p_nod->next;
 60 
 61         }
 62         ++n;
 63     }
 64 }
 65 
 66 
 67 bool s( nod *p1,nod *p2  )
 68 {
 69     return p1->word < p2->word;
 70 }
 71 
 72 void pai_xu( vector<nod *>::iterator p11,vector<nod *>::iterator q11 )
 73 {
 74     while ( p11 != q11 )
 75     {
 76         stable_sort( p11,q11,s );
 77         pai_xu( (*p11)->next->wen_jian.begin(),(*p11)->next->wen_jian.end() );
 78         ++p11;
 79     }
 80 }
 81 
 82 void shu_chu( vector<nod *>::iterator p11,vector<nod *>::iterator q11 )
 83 {
 84     while( p11 != q11 )
 85     {
 86         for ( int i = 0; i != (*p11)->num; ++i )
 87             cout << " ";
 88         cout << (*p11)->word << endl;
 89         shu_chu( (*p11)->next->wen_jian.begin(),(*p11)->next->wen_jian.end() );
 90         ++p11;
 91     }
 92 }
 93 
 94 int main()
 95 {
 96     //freopen( "in.txt","r",stdin );
 97     string str;
 98     int n;
 99     cin >> n;
100     while ( n != 0 ) 
101     {
102         cin >> str;
103         zhuan( str );
104         --n;
105     }
106     nod1 *= head;
107     pai_xu( p->wen_jian.begin(),p->wen_jian.end() );
108     p = head;
109     shu_chu( p->wen_jian.begin(),p->wen_jian.end() );
110     return 0;
111 }

posted on 2010-05-29 22:03 haozi 阅读(118) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年5月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜