HR30 Day 3: Intro to Conditional Statements

1 개요[ | ]

Day 3: Intro to Conditional Statements
해커랭크 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 {
    private static final Scanner scanner = new Scanner(System.in);
    private static boolean isWeird(int x) {
        if( x%2 == 1 ) return true;
        if( x <= 5 ) return false;
        if( x <= 20 ) return true;
        return false;
    }
    public static void main(String[] args) {
        int N = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
        scanner.close();
        System.out.println( isWeird(N) ? "Weird" : "Not Weird" );
    }
}

3 PHP[ | ]

<?php
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $N);
fclose($stdin);

if( $N%2 ==1 ) die("Weird");
if( 2<=$N && $N<=5 ) die("Not Weird");
if( 6<=$N && $N<=20 ) die("Weird");
if( $N>20 ) die("Not Weird");

4 Python[ | ]

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

def is_weird(n):
    if( n%2 == 1 ): return True
    if( 2<=n and n<=5 ): return False
    if( 6<=n and n<=20 ): return True
    if( n>20 ): return False
    return True

if __name__ == '__main__':
    N = int(input())
    if( is_weird(N) ):
        print('Weird')
    else:
        print('Not Weird')
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}