死循环?求助 不能推出循环
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
using namespace std;
/*int get_num(string str)
{
int real_num=0;
string::size_type index=0;
int leng=str.length()-1;
for(;leng!=-1;--leng)
{
real_num+=str[index]*pow(10.0,leng);
++index;
}
return real_num;
}*/
int up_count(int x,vector <int> ::iterator begin,vector <int> ::iterator end) /*上楼所需时间*/
{
return x*6+count(begin,end,x)*5;
}
int down_count(int x,vector <int> ::iterator begin,vector <int> ::iterator end) /*下楼所需时间*/
{
return x*4+count(begin,end,x)*5;
}
int main()
{
string line;
while(getline(cin,line)&&(line!= "0 "))
{
vector <int> raw;
string::iterator index=line.begin();
while(index!=line.end())
{
string num;
for(string::size_type index=0;index!=line.size();++index)
{
if(isdigit(line[index]))
{
cout < < "### " < < index < < endl;
num.push_back(line[index]);
}
else if(isspace(line[index]))
{
string empty;
int real_num=8;/*get_num(num);*/
raw.push_back(real_num);
num=empty;
cout < < index < < "这里输出num " < < endl;
}
else
{
cout < < "不合要求的输入. " < < endl;
return -1;
}
}
}
vector <int> ::iterator iter=raw.begin();
iter=raw.begin();
vector <int> stoped;
long int times=0,current=0;
while(iter!=raw.end())
{
if(count(stoped.begin(),stoped.end(),*iter)==0)
{
vector <int> ::iterator iter1=raw.begin(),iter2=raw.end();
if(*iter-current> 0)
{
times+=up_count(*iter-current,iter1,iter2);
stoped.push_back(*iter);
current=*iter;
++iter;
}
else
{
times+=down_count(current-*iter,iter1,iter2);
stoped.push_back(*iter);
current=*iter;
++iter;
}
}
else ++iter;
}
cout < < times-5 < < endl;
}
return 0;
}
还是输入的问题
不能推出循环了
"### " 和 "这里输出num " 反复出现
....
不知道是哪里的问题 求助
[解决办法]
另外,楼主在while外层和内层循环都用上了index,虽然在程序中没有任何错误,但是这种编码习惯终归是不好的,建议改换一个更能表达程序意图的命名。
[解决办法]
ls的请问,num变量有push_back方法吗?(我的机器怎么没有)