0% found this document useful (0 votes)
66 views3 pages

Inputstreamreader (System - In) ) // Bufferedreader in New Bufferedreader (New Filereader ("Jolly - TXT") )

The document contains code for several Java classes that solve different programming challenges: 1) The a_10189_JollyJumpers class checks if an integer array represents a "jolly jumper" sequence. 2) The MishkaAndGame class counts wins for Mishka and Chris in a game and determines the winner. 3) The HQ9P class checks if a string contains the characters "H", "Q", or "9". 4) The Twins class finds the maximum sum subarray in a given array. 5) The ChatRoom class checks if a given string contains the substring "hello". 6) Additional classes transform binary strings to decimal,
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views3 pages

Inputstreamreader (System - In) ) // Bufferedreader in New Bufferedreader (New Filereader ("Jolly - TXT") )

The document contains code for several Java classes that solve different programming challenges: 1) The a_10189_JollyJumpers class checks if an integer array represents a "jolly jumper" sequence. 2) The MishkaAndGame class counts wins for Mishka and Chris in a game and determines the winner. 3) The HQ9P class checks if a string contains the characters "H", "Q", or "9". 4) The Twins class finds the maximum sum subarray in a given array. 5) The ChatRoom class checks if a given string contains the substring "hello". 6) Additional classes transform binary strings to decimal,
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

public class a_10189_JollyJumpers {

public static void main(String[] args) throws Exception {


BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
// BufferedReader in = new BufferedReader(new FileReader("jolly.txt"));
for (String line; (line=in.readLine())!=null; ) {
String [] arr = line.trim().split(" +");
int n = Integer.parseInt(arr[0]);
int [] a = new int[n];
for (int i=0; i<n; i++)
a[i] = Integer.parseInt(arr[i+1]);
boolean [] b = new boolean[n-1];
for (int i=1; i<n; i++) {
int diff = Math.abs(a[i]-a[i-1])-1;
if (0<=diff && diff<n-1) b[diff]=true;
}
boolean isJolly = true;
for (int i=0; i<n-1; i++) if (b[i]==false) isJolly=false;
System.out.println(isJolly?"Jolly":"Not jolly");

}
}

public class MishkaAndGame {


public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
int part = Integer.parseInt(in.readLine().trim());
int m = 0; int c = 0;
for (int i = 0; i < part; i++) {
String line = in.readLine();
String arr[]= line.trim().split(" +");
if(Integer.parseInt(arr[0]) - Integer.parseInt(arr[1]) != 0){
if(Integer.parseInt(arr[0]) - Integer.parseInt(arr[1]) < 0)
c++;
else m++;
}
}
if(m > c) System.out.println("Mishka");
else if(c > m) System.out.println("Chris");
else System.out.println("Friendship is magic!^^");
}
}

public class HQ9P {


public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
String line=in.readLine().trim();
int aux=0;
for (int i = 0; i < line.length(); i++) {
if(line.charAt(i)=='H' || line.charAt(i)=='Q' || line.charAt(i)=='9'){
aux++;
}
}
if(aux==0) System.out.println("NO");
else System.out.println("YES");
}
}

public class Twins {


public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int n = in.nextInt(); int aux = 0;
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
int num = in.nextInt();
arr[i] = num;
aux += num;
}
Arrays.sort(arr);
int d = 0;
int cont = 0;
for (int i = n-1; i>=0; i--) {
d += arr[i];
cont++;
if (d > (aux-d)) break;
}
System.out.print(cont);
}
}

public class ChatRoom {


@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine();
if(line.matches(".*h.*e.*l.*l.*o.*")==true){
System.out.println("YES");
}
else{
System.out.println("NO");
}
Extends Application
public static void main(String[] args) {
Application.launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
Pane pane = new Pane();

//Caon
Rectangle rec = new Rectangle(2, 550, 50, 18);

pane.getChildren().addAll(pas);
pane.getChildren().addAll(rec, deco, bol);

Scene scene = new Scene (pane, 800, 600, Color.LIGHTBLUE);


primaryStage.setTitle("I love Fisica <3");
primaryStage.setScene(scene);
primaryStage.show();
}

public static int transformar(String binario) {


int decimal = 0;
for (int i = 0, j = binario.length() - 1; i < binario.length(); i++, j--) {
if (binario.charAt(i) < '0' || binario.charAt(i) > '1'){
throw new NumberFormatException("No is binary
number");
}
else{
decimal +=
(Integer.parseInt(String.valueOf(binario.charAt(i))))* Math.pow(2, j);
}
}
return decimal;
}

public static int hexToDecimal(String hex)throws HexFormatException{


int decimalValue = 0;
for (int i = 0; i < hex.length(); i++) {
if(hex.charAt(i) < 0 || hex.charAt(i) > 9 || hex.charAt(i) < 'A' ||
hex.charAt(i) > 'F'){
throw new HexFormatException();
}
char hexChar = hex.charAt(i);
decimalValue = decimalValue * 16 + hexCharToDecimal(hexChar);

}
return decimalValue;
}

You might also like