-8
I need to develop a program in C language, but I am beginner. :(
Follows the statement:
That is the context of the programme:
A smart cat walked into a messy room that needed cleaning. Instead of doing the job alone, he decides to transfer the work to his sidekick cats. The smart cat has a number of helper cats (smaller than him) inside his hat. Each helper cat also has its own helper cats (smaller than them) inside their hats. Thus, each helper cat transfers the work to be done to its own helpers. Eventually the helper cats reach a minimum size of 1. These cats of minimum size have no helpers in their hats: they are workers who must do the work themselves. Given the size of the first smart cat and the number of working cats (size 1), you should find the number of cats that do not perform any work (i.e., lazy cats larger than 1) and also determine the sum of the sizes of all cats.
Objective of the programme:
Make a program that reads from the keyboard two positive integers, T and Q. The first integer, T, indicates the size of the first smart cat and the second integer, Q, indicates the amount of working cats.
For each pair of numbers your program must produce the following output:
Quantidade de gatos que nao trabalham: 999 Tamanho total dos gatos: 999
Where 999 represents the values calculated by the program, according to the description of the problem, for the numbers read T and Q.
After printing the calculated values, your program must print a blank line and restart the procedure, ending only when 0 (zero) is entered for the T number. At the end of the processing your program should print the message "End of program".
Assumptions and restrictions
1) Before reading the T number, your program should print, on the same line, the message "Smart cat size: ", re-reading the T number (printing the orientation message again), if the entered value is negative.
2) Before reading the Q number, your program should print, on the same line, the message "Number of working cats: ", re-reading the Q number (printing the orientation message again), if the entered value is negative or zero.
3) For each pair of T and Q numbers the following rules apply: The number of cats inside each hat (of the cats that have helpers) is constant and equal to N. The size of cats inside a hat is 1/(N + 1) times the size of the cat that has the hat they are in. (For example, if N is equal to 3, the size of cats in a cat’s hat of size 16 is 4).
4) The numbers T and Q will always reflect a valid situation. That is, starting from a cat of size T, considering the cats in his hat and the cats in the hats of each helper, eventually one arrives at a quantity Q of working cats (size 1).
Example A)
The following output illustrates a valid execution of the program:Tamanho do gato esperto: -32 Tamanho do gato esperto: -961 Tamanho do gato esperto: 216 Quantidade de gatos trabalhadores: 125 Quantidade de gatos que nao trabalham: 31 Tamanho total dos gatos: 671 Tamanho do gato esperto: 5764801 Quantidade de gatos trabalhadores: 0 Quantidade de gatos trabalhadores: -2148 Quantidade de gatos trabalhadores: 1679616 Quantidade de gatos que nao trabalham: 335923 Tamanho total dos gatos: 30275911 Tamanho do gato esperto: 0 Fim de programa
Here’s the code I already have:
#include<stdio.h>
int main (void){
int T, Q;
do{
do{
printf("Tamanho do gato esperto: ");
scanf("%d", &T);
} while(T < 0);
if(T != 0){
do{
printf("Quantidade de gatos trabalhadores: ");
scanf("%d", &Q);
} while(Q <= 0);
if((T > 0) && (Q > 0)){
/* não consigo imaginar o calculo para descobrir os valores
de saída do programa */
printf("Quantidade de gatos que nao trabalham: \n");
printf("Tamanho total dos gatos: \n\n");
}
}
} while(T != 0);
if(T == 0){
printf("Fim de programa\n");
}
return 0;
}
Doubt: I can’t imagine what would be the calculation to be performed to execute the output of the program example.
Danilo, I didn’t deny it, but let me explain, the goal here is not to do everything, in case your biggest problem is the initial calculation (at least that’s what I understood), if you edit the question and give a focus on the isolated problem the question could be saved, of course it’s just my opinion and I don’t know if the other members of the site will agree.
– Guilherme Nascimento
I agree as @Guilhermenascimento you can post the full code but the question must understand an isolated part of it, and when it was solved yet another question would be to open a new question.
– WMomesso
This question seems valid to me. Could someone explain to me what is so wrong with it?
– Victor Stafusa
@Victorstafusa I did not find clear the question, and it is very difficult to isolate the problem of it and lack objectivity in relation to the calculation, at least for me this. So I voted as unclear, because I believe that there is no need to negative it, just a close and wait for the AP to make the question clearer.
– gato
@The cat problem is from the Q and the T reach the N and then the number of cats that do not work and the total size of cats. And turn that formula into an algorithm.
– Victor Stafusa
@Victorstafuses an issue by removing what is irrelevant in the question and addressing this formula and how to apply it in an algorithm would make it an optimal question.
– gato
@The problem is that this looks like college exercise, so anything that was removed could compromise the program’s understanding, and there’s a lot of teachers out there who go through very difficult exercises to decipher. In this case, I do not believe that it is the author’s fault.
– Victor Stafusa
@Victorstafusa think that giving a focus on the formulae on the part of the algorithm corresponding to it would help a lot, even keeping the text that this profuse just not to change the meaning of the question, at least separates the problem.
– gato
+1 for all irony related to the lazy cats in the hat.
– Lacobus
@Lacobus is very "hate" against cats ;P
– gato
@Vitorstafusa you’re right, it’s college issue. I did not understand the reasoning of the teacher and I can not imagine a formula to arrive at the results of the example that has in the description of the problem ://
– Danilo Antônio
@Daniloantônio posted the answer. In fact, these formulas were something very difficult to get. Your teacher must be crazy.
– Victor Stafusa
@Daniloantônio @gato @Victorstafusa: This problem is called
The Cat in the Hat
and was originally proposed by a website called Uva Online Judge. I found in the github a code inC++
that maybe solve the problem.– Lacobus