HR30 Day 2: Operators

1 개요[ | ]

Day 2: Operators
해커랭크 30 Days of Code
문제 풀이
0-9 Day e
HR30 Day 0: Hello, World.

HR30 Day 1: Data Types

HR30 Day 2: Operators

HR30 Day 3: Intro to Conditional Statements

HR30 Day 4: Class vs. Instance

HR30 Day 5: Loops

HR30 Day 6: Let's Review

HR30 Day 7: Arrays

HR30 Day 8: Dictionaries and Maps

HR30 Day 9: Recursion

2 Java[ | ]

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {
    static void solve(double meal_cost, int tip_percent, int tax_percent) {
        double tip = meal_cost * tip_percent / 100;
        double tax = meal_cost * tax_percent / 100;
        long total_cost = Math.round(meal_cost + tip + tax);
        System.out.format("The total meal cost is %d dollars.", total_cost);
    }

    private static final Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        double meal_cost = scanner.nextDouble();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
        int tip_percent = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
        int tax_percent = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
        solve(meal_cost, tip_percent, tax_percent);
        scanner.close();
    }
}

3 PHP[ | ]

<?php
function solve($meal_cost, $tip_percent, $tax_percent) {
    $tip = $meal_cost * $tip_percent / 100;
    $tax = $meal_cost * $tax_percent / 100;
    $total_cost = round($meal_cost + $tip + $tax);
    echo "The total meal cost is $total_cost dollars.";
}
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%lf\n", $meal_cost);
fscanf($stdin, "%d\n", $tip_percent);
fscanf($stdin, "%d\n", $tax_percent);
fclose($stdin);
solve($meal_cost, $tip_percent, $tax_percent);
<?php
function solve($meal_cost, $tip_percent, $tax_percent) {
    $tip = $meal_cost * $tip_percent / 100;
    $tax = $meal_cost * $tax_percent / 100;
    return round($meal_cost + $tip + $tax);
}
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%lf\n", $meal_cost);
fscanf($stdin, "%d\n", $tip_percent);
fscanf($stdin, "%d\n", $tax_percent);
fclose($stdin);
$total_cost = solve($meal_cost, $tip_percent, $tax_percent);
echo "The total meal cost is $total_cost dollars.";

4 Python[ | ]

#!/bin/python3
import math
import os
import random
import re
import sys

# Complete the solve function below.
def solve(meal_cost, tip_percent, tax_percent):
    tip = meal_cost * tip_percent / 100;
    tax = meal_cost * tax_percent / 100;
    total_cost = round(meal_cost + tip + tax)
    print( 'The total meal cost is '+str(total_cost)+' dollars.')
if __name__ == '__main__':
    meal_cost = float(input())
    tip_percent = int(input())
    tax_percent = int(input())
    solve(meal_cost, tip_percent, tax_percent)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}