谁能帮我详细解答一下C++中atoi的使用条件?
代码如下:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class BoulderRace
{
public:
int winner(vector <string> boulders, int distance);
};
int BoulderRace::winner(vector <string> boulders, int distance)
{
vector <int>count;
int min, locat;
for( int i = 0; i < boulders.size(); i++ )
{
int time = 0, k = 0, m = 0, Dis = 0;
for( int j = 0; j < boulders[i].length(); j++ )
Dis = Dis + atoi( boulders[i][j] ); //此处atoi达不到效果。
k = distance / Dis;
time = k * boulders[i].length();
Dis = Dis * k;
while( Dis < distance )
{
Dis = Dis + boulders[i][m];
time++;
m++;
}
count.push_back( time );
}
min = count[0];
locat = 0;
for( int n = 1; n < count.size(); n++ )
{
if( count[n] < min )
{
min = count[n];
locat = n;
}
}
return locat;
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class BoulderRace
{
public:
int winner(vector <string> boulders, int distance);
};
int BoulderRace::winner(vector <string> boulders, int distance)
{
vector <int>count;
int min, locat;
for( int i = 0; i < boulders.size(); i++ )
{
int time = 0, k = 0, m = 0, Dis = 0;
for( int j = 0; j < boulders[i].length(); j++ )
Dis = Dis + atoi( boulders[i][j] ); //此处atoi达不到效果。
k = distance / Dis;
time = k * boulders[i].length();
Dis = Dis * k;
while( Dis < distance )
{
Dis = Dis + boulders[i][m];
time++;
m++;
}
count.push_back( time );
}
min = count[0];
locat = 0;
for( int n = 1; n < count.size(); n++ )
{
if( count[n] < min )
{
min = count[n];
locat = n;
}
}
return locat;
}
...全文
相关推荐
atoi函数源代码
atoi函数的源代码,使你更加的了解atoi函数的功能。
itoa函数及atoi函数
itoa函数及atoi函数的区别,C++,MFC
C++使用Log4cpp
C++使用Log4cpp记录日志,包括说明文档及相关关键代码、包括log4cpp-1.1.2.tar.gz。
C++基于LOG4CPP的使用封装库
代码是C++,基于LOG4CPP进行封装日志,适用于Linux环境,使用过程时,对其进行继承即可套用其结构
C++ .h和.cpp文件总结
总结了.h文件能做什么,.cpp文件能做什么,总结了.h文件的本质,方便新手在遇到文件包含、类型声明、变量定义时能理清.h与.cpp关系,纯属个人总结文档。


