C/C++ programming learning-week 7④ cocktail therapy

Topic link

Title description

Cocktail therapy, originally referred to as "Highly Active Antiretroviral Therapy" (HAART), was proposed by Chinese American scientist Dayi He in 1996 to treat AIDS through the combined use of three or more antiviral drugs. The application of this therapy can reduce the drug resistance caused by a single drug, inhibit the replication of the virus to the greatest extent, and restore part or all of the damaged immune function of the body, thereby delaying the progression of the disease, prolonging the life of the patient, and improving the quality of life. People have proposed many improved therapies on the basis of cocktail therapy. In order to verify whether these treatments are better than cocktail therapy in terms of efficacy, they can be carried out through clinical controlled experiments. Assuming that the effective rate of cocktail therapy is x and the effective rate of the new therapy is y, if y−x is greater than 5%, the effect is better, if x−y is greater than 5%, the effect is worse, otherwise it is said that the effect is similar.

The following Suan Tou Jun gives n groups of clinical controlled experiments, of which the first group uses cocktail therapy, and the other n−1 groups are various improved therapies. Please write a program to determine how effective the various improvement treatments are.

Input format The
first line is an integer n (1<n≤20);

There are two integers in each of the remaining n rows. The first integer is the total number of clinical trials (less than or equal to 10000), and the second is the number of effective cases.

Among these n rows of data, the first behavior is the data of cocktail therapy, and the rest are data of various improvement therapies.

Output format
There are n−1 lines of output, respectively representing the effects of the corresponding improved therapy:

If the effect is better, output "better";
if the effect is worse, output "worse";
otherwise, output "same".

Sample Input

5
125 99
112 89
145 99
99 97
123 98

Sample Output

same
worse
better
same

Ideas

Assuming that the effective rate of cocktail therapy is x and the effective rate of the new therapy is y, if y−x is greater than 5%, the effect is better, if x−y is greater than 5%, the effect is worse, otherwise it is said that the effect is similar. That is to compare the effectiveness of cocktail therapy and new therapy, mathematical problems.

C language code:

#include <stdio.h>
int main()
{
    
    
	int q, i;
	double a, b, m, n;
	scanf("%d%lf%lf", &q, &a, &b);
	for(i = 1; i <= q - 1; i++)
	{
    
    
		scanf("%lf%lf", &m, &n);	//输入新疗法的数据
		if(n / m - b / a > 0.05) printf("better\n");
		else if(b / a - n / m > 0.05) printf("worse\n");
		else printf("same\n");
	}
	return 0;
}

C++ code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int n;
	while(cin >> n)
	{
    
    
		double a, b, c, d;
		cin >> a >> b;
		c = 1.0 * b / a;
		n--;
		while(n--)
		{
    
    
			cin >> a >> b;
			d = 1.0 * b / a;
			if(d - c > 0.05) cout << "better" << endl;
			else if(c - d > 0.05) cout << "worse" << endl;
			else cout << "same" << endl;
		}
	}
	return 0;
}

For students who don’t have C language foundation, you can learn the C language grammar first. I will sort it out and send it out later.
I have already written it. You can go to the C language programming column to see the content of the first week .

Other exercises this week:

C language programming column

C/C++ Programming Learning-Week 7① Calculate the value of (a+b)*c

C/C++ Programming Learning-Week 7② Calculate the value of (a+b)/c

C/C++ Programming Learning-Week 7 ③ Kakutani Conjecture

C/C++ programming learning-week 7④ cocktail therapy

C/C++ Programming Learning-Week 7 ⑤ The number of the same number as the specified number

C/C++ Programming Learning-Week 7 ⑥ Group photo effect

C/C++ Programming Learning-Week 7⑦ Word Flip

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/112912156