一段c++输入格式解析代码
思路建立两个二维数组存隐射关系,用一个递归函数判断有无锁,懒得写了
int main(int argv,char**argc)
{int num;
string input,item, temp;
vector<int> wait_id;
map<int,int> haveId_thrId;
cin >> num;
bool flag = false;
int point1,point2;
cin.get();
int thr = 0;
while(getline(cin,input)>0&&input!="")
{
point1 = input.find_first_of('\t');
point2 = input.find_last_of('\t');
item = input.substr(point1+1,point2-point1-1);
while((point1=item.find_first_of(','))>0)
{
temp = item.substr(0,point1);
item = item.substr(point1+1);
if(temp!="")
haveId_thrId[atoi(temp.c_str())] = thr;
}
if(item!=""&&item!=" ")
haveId_thrId[atoi(item.c_str())] = thr;
item = input.substr(point2+1);
if(item!=""&&item!=" ")
wait_id.push_back(atoi(item.c_str()));
}
}