PTA: best couple height difference (10 points) (c ++ version)

Experts couples through multiple sets of research data found that the optimum height difference between the couple followed a formula :( woman's height) × 1.09 = (the man's height). If so, you both height difference whether it is in hand, hugging, kissing, are the most harmonious gradient to.

Here you write a program that calculates the optimum height of his / her lovers for any user.

Input format:
input of the first row is given a positive integer N (≤10), the number of users to come to the query. Then N rows, each given in the "Gender Height" format query the user came to sex, and height, wherein "sex" is "F" for female, "M" for male; "height" is the interval [1.0, 3.0 real number between].

Output format:
for each query, the row is calculated in the optimum height for the user to couple it to retain two decimal places.

Sample input:
2
M 1.75
F. 1.8

Sample output:
1.61
1.96

Author: Chen Yue
units: Zhejiang University
Time limit: 400 ms
Memory Limit: 64 MB

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

struct lovers
{
    string a;
    double height;
};

int main()
{
    lovers p[10];
    int n, i;

    cin >> n;
    for (i = 0; i < n; i++)
        cin >> p[i].a  >> p[i].height;
    for (i = 0; i < n; i++)
    {
        if (p[i].a == "F")
            cout << fixed << setprecision(2) << p[i].height * 1.09 << endl;
        else
            cout << fixed << setprecision(2) << p[i].height / 1.09 << endl;
    }

    return 0;
}
Published 58 original articles · won praise 21 · views 595

Guess you like

Origin blog.csdn.net/qq_45624989/article/details/105418934
Recommended