⬆︎
×

[PAT-A] 1011 World Cup Betting

Hyplus目录

Java

import java.util.Scanner;

public class Main {
    private static final String[] words = {"W ", "T ", "L "};

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double res = 1.0;

        for (int i = 0; i < 3; i++) {
            double x, max_x = 0;
            int idx = 0;
            for (int j = 0; j < 3; j++) {
                x = scanner.nextDouble();
                if (x > max_x) {
                    max_x = x;
                    idx = j;
                }
            }
            res *= max_x;
            System.out.print(words[idx]);
        }

        System.out.printf("%.2f\n", (res * 0.65 - 1) * 2);
    }
}

C++

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

string words[5] = {"W ", "T ", "L "};

int main() {
    double res = 1.0;
    for (int i = 0; i < 3; ++i) {
        double x, max_x = 0;
        int idx = 0;
        for (int j = 0; j < 3; ++j) {
            scanf("%lf", &x);
            if (x > max_x) {
                max_x = x;
                idx = j;
            }
        }
        res *= max_x;
        cout << words[idx];
    }

    printf("%.2f\n", (res * 0.65 - 1) * 2);

    return 0;
}

发表评论