Posted on 2012-09-21 16:25
弘毅 阅读(60)
评论(0) 编辑 收藏 引用
我的第一篇文章,很水的,目地是给green hand 一点点帮助吧。

code
1 #include <iostream>
2 #include <cstring>
3 #include <cstdio>
4 #include <vector>
5 #include <list>
6 using namespace std;
7 #define M 110
8 #define N 10000
9 vector<vector<int> >v;
10 list<list<int> >L;
11 list<list<int> >::iterator it;
12 struct Edge{
13 int c,next;
14 }edge[N];
15 int head[M],n,k;
16
17 void insert(int i,int c){
18 edge[k].c=c;
19 edge[k++].next=head[i];
20 head[i]=k-1;
21 }
22 int main(){
23 while(cin>>n){
24 memset(head,-1,sizeof(head));
25 v.clear();
26 L.clear();
27 k=0;
28 for(int i=0;i<n;i++){
29 vector<int>a;
30 list<int>l;
31 int m;
32 cin>>m;
33 while(m--){
34 int x;
35 cin>>x;
36 insert(i,x);
37 a.push_back(x);
38 l.push_back(x);
39 }
40 v.push_back(a);
41 L.push_back(l);
42 }
43 cout<<"vector==>"<<endl;
44 for(int i=0;i<n;i++){
45 for(int j=0;j<v[i].size();j++)
46 cout<<v[i][j]<<" ";
47 cout<<endl;
48 }
49 cout<<"list==>"<<endl;
50 for(it=L.begin();it!=L.end();it++){
51 list<int>l=*it;
52 list<int>::iterator ii;
53 for(ii=l.begin();ii!=l.end();ii++)
54 cout<<*ii<<" ";
55 cout<<endl;
56 }
57 cout<<"head==>"<<endl;
58 for(int i=0;i<n;i++){
59 for(int top=head[i];top!=-1;top=edge[top].next){
60 cout<<edge[top].c<<" ";
61 top=edge[top].next;
62 }
63 cout<<endl;
64 }
65 }
66 return 0;
67 }
68