您的位置:首页 > 理论基础 > 计算机网络

http://projecteuler.net/problem=40 [Answer:210]

2011-12-10 11:42 417 查看
#include <iostream>

using namespace std;

int NthDigit( int n )
{
int nNumberLength = 1;
int nNumberCount = 9;
int nNumberBegin = 1;
while ( n > nNumberLength * nNumberCount )
{
n -= nNumberLength * nNumberCount;
nNumberLength += 1;
nNumberCount *= 10;
nNumberBegin *= 10;
}

int nIndex = (n - 1) / nNumberLength;
int nNumber = nNumberBegin + nIndex;
int times = (nNumberLength - 1) - ((n - 1) - nIndex * nNumberLength);
while ( times > 0 )
{
--times;
nNumber /= 10;
}

return nNumber % 10;
}

int main()
{
int result = 1;
result *= NthDigit( 1 );
result *= NthDigit( 10 );
result *= NthDigit( 100 );
result *= NthDigit( 1000 );
result *= NthDigit( 10000 );
result *= NthDigit( 100000 );
result *= NthDigit( 1000000 );
cout << result << endl;
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  include