各位数是6的数,跟其他位置交互后是该数的4倍,求此数字(源码)
c++吧
全部回复
仅看楼主
level 5
yydy1124 楼主
///////////刚看到有这个题目,写了一下,VS2010测试通过。结果:153846
////本打算用移位、或、与方式实现,没有行通,请补充
#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int maxValue = int( std::pow( 2.0, 31 ) ) - 1;
for ( unsigned int i = 16; i < maxValue; i++ )
{
stringstream stream;
stream << i;
string str;
stream >> str;
if( str.size() - 1 != str.find_last_of( '6' ) )continue;
for( size_t j = str.size() - 1; j > 0; j-- )
{
char temp = str[ j ];
str[ j ] = str[ j - 1 ];
str[ j - 1 ] = temp;
if( atoi( str.c_str() ) == i * 4 )cout << i << endl;
}
}
return 0;
}
2014年03月22日 10点03分 1
level 7
这个题我做了,没有要调用这么多库函数吧?
2014年03月22日 12点03分 2
1