In this HackerRank Day 3: Intro to Conditional Statements problem solution Given an integer, n, perform the following conditional actions:

If n is odd, print Weird
If n is even and in the inclusive range of 2 to 5, print Not Weird
If n is even and in the inclusive range of 6 to 20, print Weird
If n is even and greater than 20, print Not Weird
Complete the stub code provided in your editor to print whether or not n is weird.

HackerRank Day 3: Intro to Conditional Statements problem solution

Problem solution in Python programming.

#!/bin/python3

import sys


n = int(input().strip())

if (n % 2 != 0):
    print("Weird")
elif(n <= 5):
    print("Not Weird")
elif(n <= 20):
    print("Weird")
else:
    print("Not Weird")



Problem solution in Java programming.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
   
   public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt(); 
      scan.close();
      String ans="";
          
      // if 'n' is NOT evenly divisible by 2 (i.e.: n is odd)
      if(n%2==1){
         ans = "Weird";
      }
      else{
         // Complete the code 
          for(int i = 2; i <= 5; i += 2){
              if(n == i){
                  ans = "Not Weird";
              }
          }
          
          for(int i = 6; i <= 20; i += 2){
              if(n == i){
                  ans = "Weird";
              }
          }
          
          if(n > 20)
              ans = "Not Weird";
      }
      System.out.println(ans);
   }
}




Problem solution in C++ programming.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;


int main(){
    int N;
    cin >> N;
    
    
    if ( N%2 == 1 ) {   //odd case, thus the rest must be even
        cout << "Weird";
    } else if ( N >= 2 && N <=5 ) {    
        cout << "Not Weird";
    } else if ( N >= 6 &&  N <=20 ) {
        cout << "Weird";
    } else {       // N > 20 and even
        cout << "Not Weird";
    }
    
    
    
    
    
    return 0;
}



Problem solution in C programming.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int N; 
    scanf("%d",&N);
    
    if(N%2 ==1 ){
        printf("Weird\n");
    }else if(N%2 ==0 && N>=2 && N<=5){
        printf("Not Weird\n");
    }else if(N%2 == 0 && N>=6 && N<=20){
        printf("Weird\n");
    }else{
        printf("Not Weird\n");
    }
    
    return 0;
}



Problem solution in Javascript programming.

process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
    var N = parseInt(readLine());
    if(N % 2 == 1){
        console.log("Weird");
    }else if(N >= 2 && N <= 5 && (N % 2 == 0)){
        console.log("Not Weird")
    }else if(N >= 6 && N <= 20 && (N % 2 == 0)){
        console.log("Weird");
    }else if(N > 20 && (N % 2 == 0)){
        console.log("Not Weird");
    }
}