Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions algo1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// hackerrank rat and mouse question

import java.util.*;
import java.math.*;

public class Solution {

public static String solve(int x, int y, int z) {
String winner = "";
int a = Math.abs(z - x);
int b = Math.abs(z - y);

if (a == b) {
winner = "Mouse C";
}
else if (a < b) {
winner = "Cat A";
}
else {
winner = "Cat B";
}

return winner;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
while (q-- > 0) {
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();

System.out.println(solve(x, y, z));
}
in.close();
}
}
27 changes: 27 additions & 0 deletions algo2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// grading students question hackerrank

import java.util.*;

public class Solution {

public static int getRoundedGrade(int grade) {
if (grade >= 38) {
int mod5 = grade % 5;
if (mod5 > 2) {
grade += 5 - mod5;
}
}

return grade;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int a0 = 0; a0 < n; a0++){
int grade = in.nextInt();
System.out.println(getRoundedGrade(grade));
}
in.close();
}
}
31 changes: 31 additions & 0 deletions algo3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// chocolate feast question hackerrnak

import java.util.*;

public class Solution {

static int maximumChocolates(int n, int c, int m) {

int cupcakes = n / c;

int totalCupcakes = cupcakes;

while (cupcakes >= m) {
cupcakes -= m;

totalCupcakes++;
cupcakes++;
}

return totalCupcakes;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0; i < t; i++){
System.out.println(maximumChocolates(in.nextInt(), in.nextInt(), in.nextInt()));
}
in.close();
}
}