Valley bath brush our questions (four) - Array

P1046 Tao Tao picking apples

Title Description

Tao Tao family's yard has an apple tree, every autumn tree will bear 10 apples. Apple ripe, Tao Tao will go apple-picking. Tao Tao has a 30 cm high bench, when she can not directly hand to pick apples and they will try again stepped on the bench.
Now known 10 apples to the ground level, and Tao Tao handle straight time to reach the maximum height, Tao Tao please help her to count the number of apples to pick. Assuming that she met apples, apple will fall.

Code

#include <iostream>
int main()
{
    using namespace std;
    int a[10];
    for (int i = 0; i < 10; i++)
        cin >> a[i];
    int hight;
    cin >> hight;
    int count = 0;
    for (int j = 0; j < 10; j++)
        if (a[j] <= (hight + 30))
            count++;
    cout << count << endl;
    return 0;
}

P1047 tree outside the school

Title Description

A school outside the gate length L of the road with a row of trees, the interval between each two adjacent trees are 11 m. We can put the road number as a shaft, one end of the road at a position number 0 of the shaft, the other end position L; each integer number axis point, i.e., 0,1,2, ..., L, are a tree species.
Because there are some areas on the road to be used to build the subway. These areas represent the start and end points with number axis thereof. Coordinate any known starting and ending points of a region are integers, there may be overlap between the partial regions. Now, we these regions tree (including two trees at the end regions) removed. Your task is the calculation of these trees are removed, how many trees there are on the road.

Code

#include <iostream>
int main()
{
    using namespace std;
    int length;
    cin >> length;
    int a[10000];
    for (int i = 0; i <= length; i++)
        a[i] = 1;
    int num;
    cin >> num;
    for (int j =0; j < num; j++)
    {
        int c, b;
        cin >> c >> b;
        for (int k = c; k <= b; k++)
            a[k] = 0;
    }
    int sum = 0;
    for (int l = 0; l <= length; l++)
        sum += a[l];
    cout << sum << endl;
}

P1427 fish numbers game

Title Description

Fish was recently asked to participate in a numbers game, asking it to see a string of numbers (not necessarily the length, ending in 0, up to more than 100 digital does not exceed 2 32 -1), and then remember to read the opposite of out (indicating the end of the numbers 0, do not read out). This small fish is memory that point it is too difficult, you do not think about just how much the overall head of fish, some of which still delicious meat! So please help fish programming to solve this problem.

Code

#include <iostream>
int main()
{
	using namespace std;
	int a[100];
	int i = -1;
	do {
		i++;
		cin >> a[i];
	} while (a[i] != 0);
	for (i--; i >=0; i--)
		cout << a[i] << " ";
	return 0;
}

P1428 fish than cute

Title Description

Than people, mad people; fish than fish, dead fish difficult. Fish recently participated in a "lovely than" race, than the extent of each fish cute. Fish participating in a row from left to right, toward the left side of the head are then each fish will get an integer value representing cuter this fish, it is clear that the larger the integer, the more lovely this fish, and the extent of any two cute fish as possible. Since all are toward the left side of the head, so that each fish can only be seen in the extent of its lovely fish left their hearts are in the calculation, there are how many fish as their own cute in their vision range. Please help these lovely fish brain but not enough of the fish they calculate.

Code

#include <iostream>
int main()
{
	using namespace std;
	int a[100];
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	int b[100];
	for (int m = 0; m < n; m++)
		b[m] = 0;
	for (int j = 0; j < n; j++)
	{
		for (int k = 0; k <j; k++)
			if (a[k] < a[j])
				b[j]++;
	}
	for (int l = 0; l < n; l++)
		cout << b[l] << " ";
	return 0;
}

P2141 abacus and mental arithmetic test

Title Description

Abacus is a technique of calculating a change in the brain simulated abacus operations accomplished by quickly. Abacus, both to the development of intelligence, but also to bring a lot of convenience to everyday life, and thus gained popularity in many schools.

A school teacher abacus and mental arithmetic test method using a quick study mental arithmetic ability of the addition. He randomly generate a set of positive integers, the number of collection vary, and then ask students to answer: how many of these number, set exactly equal to the other two (different) and the number of?

Recently a teacher some quiz to help you find answers.

(The title is a universal 2014NOIP T1)

Code

#include <iostream>
int main()
{
	using namespace std;
	int n;
	cin >> n;
	int a[100];
	for (int l = 0; l < n; l++)
		cin >> a[l];
	int count = 0;
	int b[100];
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			for (int k = 0; k < n; k++)
				if (a[k] == a[i] + a[j] && b[k] != 1)
				{
					count++;
					b[k] = 1;
				}
	cout << count << endl;
	return 0;
}

P1567 Statistical Days

Title Description

Hot summer, KC very unhappy. He would rather endure the arctic cold, do not want to endure Xiamen summer. Recently, he began to study changes in the weather. He hoped that with the weather forecast future results of the study.

Experience hardships, he collected a continuous N (1≤N≤10 6 maximum temperature data).

Now, he wants to know the maximum number of consecutive days of maximum temperatures have been rising.

Code

#include <iostream>
int main()
{
	using namespace std;
	int num;
	cin >> num;
	int a[1000000];
	for (int i = 0; i < num; i++)
		cin >> a[i];
	int flag = 0;
	int result = 0;
	int days = 0;
	for (int j = 0; j < num - 1; j++){
		if (a[j] < a[j + 1]){
			days++;
			flag = 0;
		}
		else
			if (flag == 0){
				if (result < days)
					result = days;
				days = 0;
				flag = 1;
			}
	}
	cout << result + 1 << endl;
	return 0;
}
Published 17 original articles · won praise 10 · views 392

Guess you like

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