Description
There is a road, which has N blocks.
You have to plant trees and grasses along the road, such that each block along the road has either a tree or a bush of grass.
You are given a list of k different types of trees.
Each type of tree is associated with a distance d, which means that such type of trees must be planted every d blocks.
Moreover, all types of trees must be planted from the beginning block of the road.
If two or more types of trees are assigned to be planted in the same block, you only need to plant the tree whose type appears later.
If a block has no tree to plant, plant a bush of grass.
You can use the hint to design your code
Hint:
#include
int main()
{
int N, typeNum;
int i;
char blocks[100];
char tree;
int d;
/* declare any other variable if required. */
scanf("%d", &N); // read number of blocks, N
scanf("%d", &typeNum); // read number of trees' types
/* initialize the blocks */
/* add your code here */
getchar(); // read '\n'
for(i=0; iblocks[i]);
printf("\n");
return 0;
}
Input
(Number of blocks N.)
(Number of trees’ types, k.)
(tree type1, distance d1)
(tree type2, distance d2)
(..., ...)
"tree type" will be only a character.
1 <= N <= 100
1 <= k <= 10
Output
The final appearance of the road.
Notice that you have to use character "G" to represent grass.
Tags