首页 > 其他 > 详细

Project Euler:Problem 40 Champernowne's constant

时间:2015-06-04 13:55:00      阅读:163      评论:0      收藏:0      [点我收藏+]

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;
}


Project Euler:Problem 40 Champernowne's constant

原文:http://blog.csdn.net/youb11/article/details/46358267

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!