forked from ows-ali/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ows-ali#180 from petridisa/master
Add gameWithCells in java Thanks :)
- Loading branch information
Showing
6 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters