Skip to content

Commit

Permalink
Merge pull request ows-ali#180 from petridisa/master
Browse files Browse the repository at this point in the history
Add gameWithCells in java Thanks :)
  • Loading branch information
ows-ali authored Jan 15, 2019
2 parents 9477695 + 25f483f commit a421041
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Hackerrank/bon-appetit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Solution {

// Complete the bonAppetit function below.
static void bonAppetit(List<Integer> bill, int k, int b) {
int total=0;
for(int i=0;i<bill.size();i++){
if(i!=k)total+=bill.get(i);
}total/=2;
if(total==b)System.out.println("Bon Appetit");
else System.out.println(b-total);
}

public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

String[] nk = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");

int n = Integer.parseInt(nk[0]);

int k = Integer.parseInt(nk[1]);

List<Integer> bill = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList());

int b = Integer.parseInt(bufferedReader.readLine().trim());

bonAppetit(bill, k, b);

bufferedReader.close();
}
}
54 changes: 54 additions & 0 deletions Hackerrank/compare-the-triplets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Solution {

// Complete the compareTriplets function below.
static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) {
List <Integer> score = new ArrayList<>();
int ascore=0;int bscore=0;
for(int i=0;i<3;i++){
if(a.get(i)>b.get(i))ascore++;
else if(a.get(i)==b.get(i))continue;
else bscore++;
}
score.add(0,ascore);
score.add(1,bscore);
return score;

}

public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

List<Integer> a = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList());

List<Integer> b = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList());

List<Integer> result = compareTriplets(a, b);

bufferedWriter.write(
result.stream()
.map(Object::toString)
.collect(joining(" "))
+ "\n"
);

bufferedReader.close();
bufferedWriter.close();
}
}
55 changes: 55 additions & 0 deletions Hackerrank/day-of-the-programmer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Solution {

// Complete the dayOfProgrammer function below.
static String dayOfProgrammer(int year) {
boolean leap=false;
String day;
int d=13,m=9;
leap =(year%4==0);
if(year>1918){
if(year%400==0)leap=true;
else if(year%4==0&&year%100!=0)leap=true;
else leap=false;
}
if(leap)d--;
if(year==1918)d=26;
if(d<10&&m<10)
day= "0"+d+".0"+m+"."+year;
else if(d<10)
day= "0"+d+"."+m+"."+year;
else if(m<10)
day= d+".0"+m+"."+year;
else
day= d+"."+m+"."+year;
return day;


}

public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

int year = Integer.parseInt(bufferedReader.readLine().trim());

String result = dayOfProgrammer(year);

bufferedWriter.write(result);
bufferedWriter.newLine();

bufferedReader.close();
bufferedWriter.close();
}
}
40 changes: 40 additions & 0 deletions Hackerrank/gameWithCells.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Solution {

/*
* Complete the gameWithCells function below.
*/
static int gameWithCells(int n, int m) {
int counter=0;
for(int i=0;i<n;i+=2){
for(int j=0;j<m;j+=2){
counter++;
}
}
return counter;
}

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

String[] nm = scanner.nextLine().split(" ");

int n = Integer.parseInt(nm[0].trim());

int m = Integer.parseInt(nm[1].trim());

int result = gameWithCells(n, m);

bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();

bufferedWriter.close();
}
}
44 changes: 44 additions & 0 deletions Hackerrank/kangaroo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 {

// Complete the kangaroo function below.
static String kangaroo(int x1, int v1, int x2, int v2) {
if(v1==v2 && x1!=x2)return "NO";
if(v2>v1)return "NO";
if((x2-x1)%(v1-v2)==0)return "YES";
return "NO";

}

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

String[] x1V1X2V2 = scanner.nextLine().split(" ");

int x1 = Integer.parseInt(x1V1X2V2[0]);

int v1 = Integer.parseInt(x1V1X2V2[1]);

int x2 = Integer.parseInt(x1V1X2V2[2]);

int v2 = Integer.parseInt(x1V1X2V2[3]);

String result = kangaroo(x1, v1, x2, v2);

bufferedWriter.write(result);
bufferedWriter.newLine();

bufferedWriter.close();

scanner.close();
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ In this repository, you can find the solutions (as source code) for the problems
| [Deepanshu Sinha](https://github.com/sinhaDroid) <br> <img src="https://github.com/sinhaDroid.png" width="100" height="100"> | India | Python, Android, Java, Javascript | https://www.linkedin.com/in/deepanshu-sinha/ |
| [Jared Moser](https://github.com/JM0S3R) <br> <img src="https://github.com/JM0S3R.png" width="100" height="100"> | United States | C++, Javascript | |
| [Matei Oltean](https://github.com/Matei13) <br> <img src="https://github.com/Matei13.png" width="100" height="100"> | France | OCaml | |
| [Andreas Petridis](https://github.com/petridisa) <br> <img src="https://github.com/petridisa.png" width="100" height="100"> | Greece | Java | |
| [Lam Tran](https://github.com/Lam7150) <br> <img src="https://avatars2.githubusercontent.com/u/29765024?s=460&v=4" width="100" height="100"> | United States | Java | http://linkedin.com/in/lamgtran/ |


Expand Down

0 comments on commit a421041

Please sign in to comment.