HR30 Day 26: Nested Logic

1 개요[ | ]

HR30 Day 26: Nested Logic

해커랭크 30 Days of Code
문제 풀이
20-29 Day e
HR30 Day 20: Sorting

HR30 Day 21: Generics

HR30 Day 22: Binary Search Trees

HR30 Day 23: BST Level-Order Traversal

HR30 Day 24: More Linked Lists

HR30 Day 25: Running Time and Complexity

HR30 Day 26: Nested Logic

HR30 Day 27: Testing

HR30 Day 28: RegEx, Patterns, and Intro to Databases

HR30 Day 29: Bitwise AND

2 Java[ | ]

import java.io.*;
import java.util.*;

public class Solution {
    static int getFine(int actualDay, int actualMonth, int actualYear, int expectedDay, int expectedMonth, int expectedYear) {
        if(actualYear > expectedYear) return 10000;
        if(actualYear < expectedYear) return 0;
        if(actualMonth > expectedMonth) {
            return 500 * (actualMonth-expectedMonth);
        }
        if(actualMonth < expectedMonth) return 0;
        if(actualDay > expectedDay) {
            return 15 * (actualDay-expectedDay);
        }
        return 0;
    }
    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int actualDay = sc.nextInt();
        int actualMonth = sc.nextInt();
        int actualYear = sc.nextInt();
        int expectedDay = sc.nextInt();
        int expectedMonth = sc.nextInt();
        int expectedYear = sc.nextInt();
        int fine = getFine(actualDay, actualMonth, actualYear, 
            expectedDay, expectedMonth, expectedYear);
        System.out.println(fine);
    }
}

3 PHP[ | ]

<?php
function get_fine($actualDay, $actualMonth, $actualYear, $expectedDay, $expectedMonth, $expectedYear) {
    if($actualYear > $expectedYear) return 10000;
    if($actualYear < $expectedYear) return 0;
    if($actualMonth > $expectedMonth) {
        return 500*($actualMonth-$expectedMonth);
    }
    if($actualMonth < $expectedMonth) return 0;
    if($actualDay > $expectedDay) {
        return 15*($actualDay-$expectedDay);
    }
    return 0;
}
$_fp = fopen("php://stdin", "r");
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
fscanf($_fp, '%d %d %d', $actualDay, $actualMonth, $actualYear);
fscanf($_fp, '%d %d %d', $expectedDay, $expectedMonth, $expectedYear);
$fine = get_fine($actualDay, $actualMonth, $actualYear, $expectedDay, $expectedMonth, $expectedYear);
echo $fine;
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}