Valley bath brush our questions (three) - cycling! cycle! cycle!

P1008 trifecta

Title Description

The 1,2, ⋯, 9 9 number divided into three groups, each consisting of three digits 3 and 3 so that these constitute a three-digit number: 2: 3 ratio, satisfy the conditions of the test to obtain all three three digits.

Code

#include <iostream>
int main()
{
	using namespace std;
	for (int i = 123; i <= 333; i++)
	{
		int j = 2 * i;
		int k = 3 * i;
		if ((i / 100) + (i / 10 % 10) + (i % 10) + (j / 100) + (j / 10 % 10) + (j % 10) + (k / 100) + (k / 10 % 10) + (k % 10) == 45 && (i / 100) * (i / 10 % 10) * (i % 10) * (j / 100) * (j / 10 % 10) * (j % 10) * (k / 100) * (k / 10 % 10) * (k % 10) == 362880)
			cout << i << " " << j << " " << k << endl;
	}
	return 0;
}

P1035 Summation

Title Description

Known: S_n = 1 + 1/2 + 1/3 + ... + 1 / n. Clearly for any integer k, when n is large enough, Sn> k.
We are now given an integer k, calculate a required minimum n, such that Sn> k.

Code

#include <iostream>
int main()
{
	using namespace std;
	int k;
	int n;
	double sum = 0;
	cin >> k;
	for (n = 1; sum <= k; n++)
		sum += (double)1 / n;
	cout << n - 1 << endl;
	return 0;
}

P1423 Xiaoyu swimming

Title Description

Xiaoyu happy in swimming, but she soon found that sad, their strength is not enough, swimming tired oh. The first step is known Xiaoyu can swim two meters, but with more and more tired, more and more small effort, she followed every step can only swim a distance of 98% in the previous step. Now Xiaoyu want to know, if you want to swim to place distance x meters, how many steps she needs to swim yet. Please programming to solve this problem.

Code

#include <iostream>
int main()
{
	using namespace std;
	double meter;
	cin >> meter;
	int step;
	double destance = 2;
	double sum = 0;
	for (step = 0; sum < meter; step++)
	{
		sum += destance;
		destance *= 0.98;
	}
	cout << step << endl;
	return 0;
}

P1424 fish voyage (improved version)

Title Description

There was a small fish, which normally swim 250 kilometers a day, weekends (Saturday and Sunday practice), assuming that counting from the start of week x (1≤x≤7), over the n-(n ≤ 10 6 ) days later, the cumulative total of fish how many kilometers swim it?

Code

#include <iostream>
int main()
{
	using namespace std;
	int x;
	int n;
	int destance = 0;
	cin >> x >> n;
	for (int i = 0; i < n; i++, x++)
	{
		if (x != 6 && x != 7)
			destance += 250;
		if (x == 7)
			x = 0;
	}
	cout << destance << endl;
	return 0;
}

P1980 Counting Problems

Title Description

Calculate all integer in the range 1 to n, the digital x (0≤x≤9) there have been a total of how many times? For example, 1 to 11, in 1,2,3,4,5,6,7,8,9,10,11 i.e., number 1 appears four times.

Code

#include <iostream>
int main()
{
	using namespace std;
	int n;
	int x;
	int t;
	int b;
	int count = 0;
	cin >> n >> x;
	for (int i = 1; i <= n; i++)
	{
		t = i;
		while (t != 0)
		{
			b = t % 10;
			t = t / 10;
			if (b == x)
				count++;
		}
	}
	cout << count << endl;
	return 0;
}
Published 17 original articles · won praise 10 · views 409

Guess you like

Origin blog.csdn.net/acslsr/article/details/104080680