Pyl0j

雪花统治的世界,那是分形几何啊

   :: 首页  :: 新随笔  ::  :: 订阅 订阅  :: 管理

  之前用惯了指针型的前向星,每一次都得手打20行代码,十分不爽。之后学了vector,腰不酸了,腿不疼了,写代码也方便多了。

 1 //前向星模板
 2 #include <cstdio>
 3 #include <vector>
 4 using namespace std;
 5 
 6 const int MAXN=100;
 7 struct node {
 8     int to;
 9     int w;
10 };
11 vector <node> map[MAXN];
12 
13 int main() {
14     int n,m;
15     scanf("%d%d",&m,&n);
16     
17     //summon the map
18     int k,i,j,w;
19     for (k=1;k<=m;k++) {
20         scanf("%d%d%d",&i,&j,&w);
21         node e;
22         e.to=j;
23         e.w=w;
24         map[i].push_back(e);
25     }
26     
27     printf("-----------------\n");
28     //print the map
29     vector <node>::iterator it;
30     for (i=1;i<=n;i++) {
31         for (it=map[i].begin();it!=map[i].end();it++) {
32             node tmp= *it;
33             printf("%d %d %d\n",i,tmp.to,tmp.w);
34         }
35     }
36     
37     return 0;
38 }

  这就是一个完整的,支持读入写出的前向星代码了。仅供参考。

posted on 2017-10-07 17:54  Pyloj  阅读(318)  评论(0编辑  收藏  举报