Tuesday, February 27, 2018

HackerRank - Grading Students Problem

This is a HackerRank Problem. You can find it HERE

Question

At HackerLand University, a passing grade is any grade 40 points or higher on a 100 point scale. Sam is a professor at the university and likes to round each student’s grade according to the following rules:
  • If the difference between the grade and the next higher multiple of 5 is less than 3, round to the next higher multiple of 5
  • If the grade is less than 38, don’t bother as it’s still a failing grade
Automate the rounding process then round a list of grades and print the results. ... Get details HERE

Solution


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

public class Solution {

    static int[] solve(int[] grades){
        int[] result = new int[grades.length];
        for (int i = 0; i < grades.length; i++) {
            if (grades[i] < 38) {
                result[i] = grades[i];
            } else {
                int rem = grades[i] % 5;
                if (rem < 3) {
                    result[i] = grades[i];
                } else {
                    result[i] = grades[i] + 5 - rem;
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] grades = new int[n];
        for(int grades_i=0; grades_i < n; grades_i++){
            grades[grades_i] = in.nextInt();
        }
        int[] result = solve(grades);
        for (int i = 0; i < result.length; i++) {
            System.out.print(result[i] + (i != result.length - 1 ? "\n" : ""));
        }
        System.out.println("");
    }
}








Tuesday, February 20, 2018

Intellij IDEA Shortcuts

Show Implementing Classes

To see all the classes which implement an interface, place your cursor on the interface name and push Ctrl+Alt+B. This will show all the classes implementing the interface.

See All Methods in Current Class

Press F12 to see all the methods in current class.

Go to Line Number

Press Ctrl+G. A dialog will pop up. Enter your line number to go to that line. You can also give column number after : to jump to that column of the line number.

Move Lines

Place cursor in the line which you want to move. Then press Shift+Alt+Up Arrow or Down Arrow to move the line up or down. To move multiple lines at once, select multiple lines before pressing the key combinations.

Delete Lines

Place cursor in the line which you want to delete. Then press Ctrl+y to delete the line. To delete multiple lines at once, select multiple lines before pressing the key combinations.

Duplicate Lines

Place cursor in the line which you want to duplicate. Then press Ctrl+d to duplicate the line. To duplicate multiple lines at once, select multiple lines before pressing the key combinations.