帮小弟我优化一下代码 这个执行速度太长了
帮我优化一下代码 这个执行速度太长了
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<sstream>
using namespace std;
struct HEAD
{
string version;
string target_data;
string major_data;
string create_date;
};
struct INFO
{
string id;
string name;
string yomi;
string section;
string open_date;
string distance;
string prefecture;
string supplement;
string comment;
};
struct ANDL
{
string a1;
string a2;
string a3;
string a4;
string a5;
};
struct PART
{
string seq;
int nCount;
vector<ANDL> Andl;
};
struct GROP
{
struct INFO info;
int n_part;
vector<PART> Part;
int n_facil;
vector<string> Facil;
};
struct ANDL andl;
struct HEAD head;
struct PART part;
struct GROP grop;
int main()
{
vector<GROP> data;
string str,src,substr;
int nCount = 0, mCount = 0, pCount = 0;
int j;
string filename = "openroad.txt";
ifstream infile(filename.c_str());
if(infile.fail())
{
cerr<<"can,t not open fail";
return -1;
}
while(getline(infile, str))
{
int index = 0;
string::size_type m = str.find('\t');
src = str.substr(0,m);
if( src == "@info" )
{
j = 0;
data.push_back(grop);
grop.n_part = 0;
grop.n_facil = 0;
}
else if( src == "@part" )
{
index = 0;
grop.n_part++;
grop.Part.push_back(part);
}
else if( src == "@id" )
{
part.nCount = 0;
grop.info.id = str.substr(m);
}
else if( src == "@seq" )
{
// grop.n_part++;
part.seq = str.substr(m);
}
else if( src == "@l" )
{
stringstream ss(str);
while(getline(ss,substr,'\t'))
{
if(index == 0)
andl.a1 = substr;
if(index == 1)
andl.a2 = substr;
if(index == 2)
andl.a3 = substr;
if(index == 3)
andl.a4 = substr;
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<sstream>
using namespace std;
struct HEAD
{
string version;
string target_data;
string major_data;
string create_date;
};
struct INFO
{
string id;
string name;
string yomi;
string section;
string open_date;
string distance;
string prefecture;
string supplement;
string comment;
};
struct ANDL
{
string a1;
string a2;
string a3;
string a4;
string a5;
};
struct PART
{
string seq;
int nCount;
vector<ANDL> Andl;
};
struct GROP
{
struct INFO info;
int n_part;
vector<PART> Part;
int n_facil;
vector<string> Facil;
};
struct ANDL andl;
struct HEAD head;
struct PART part;
struct GROP grop;
int main()
{
vector<GROP> data;
string str,src,substr;
int nCount = 0, mCount = 0, pCount = 0;
int j;
string filename = "openroad.txt";
ifstream infile(filename.c_str());
if(infile.fail())
{
cerr<<"can,t not open fail";
return -1;
}
while(getline(infile, str))
{
int index = 0;
string::size_type m = str.find('\t');
src = str.substr(0,m);
if( src == "@info" )
{
j = 0;
data.push_back(grop);
grop.n_part = 0;
grop.n_facil = 0;
}
else if( src == "@part" )
{
index = 0;
grop.n_part++;
grop.Part.push_back(part);
}
else if( src == "@id" )
{
part.nCount = 0;
grop.info.id = str.substr(m);
}
else if( src == "@seq" )
{
// grop.n_part++;
part.seq = str.substr(m);
}
else if( src == "@l" )
{
stringstream ss(str);
while(getline(ss,substr,'\t'))
{
if(index == 0)
andl.a1 = substr;
if(index == 1)
andl.a2 = substr;
if(index == 2)
andl.a3 = substr;
if(index == 3)
andl.a4 = substr;