您的位置:首页 > 其它

Project Euler:Problem 40 Champernowne's constant

2015-06-04 11:25 330 查看
An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021...
It can be seen that the 12th digit of the fractional part is 1.
If dn represents the nth digit of the fractional part, find the value of the following expression.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000

#include <iostream>
#include <string>
using namespace std;

string int_str(int a)
{
	string res = "";
	while (a)
	{
		char s = a % 10 + '0';
		res = s + res;
		a /= 10;
	}
	return res;
}

int main()
{
	string s = "";
	for (int i = 1; i <= 1000000; i++)
	{
		s = s + int_str(i);
	}
	int ans = 1;
	ans = (s[1 - 1] - '0')*(s[10 - 1] - '0')*(s[100 - 1] - '0')*(s[1000 - 1] - '0')*(s[10000 - 1] - '0')*(s[100000 - 1] - '0')*(s[1000000 - 1] - '0');
	cout << ans << endl;
	system("pause");
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: