处理Newman社交网络的数据

来源:互联网 发布:上海茜昶网络培训的 编辑:程序博客网 时间:2024/06/04 18:40

将Newman社交网络数据集格式转换为普通数据集程序,以备以后使用
#include<fstream>#include<iostream>#include<string>#include<sstream>using namespace std;int main(){ifstream in("../data/data/co_author.txt",ios_base::in);ofstream out("../data/data/co_author",ios_base::out|ios_base::app);string line;int i=0;while(getline(in,line)){if(line[2]=='e'|line[2]=='['|line[2]==']');else{string word,vertex;istringstream stream(line);stream>>word;stream>>vertex;if(i==0){i++;out<<vertex<<"\t";}else if(i==1){i++;out<<vertex<<"\t";}else if(i==2){i=0;out<<vertex<<"\n";}}}in.close();out.close();}


原创粉丝点击