Skip to content

Instantly share code, notes, and snippets.

@hiramekun
Last active May 14, 2018 23:51
Show Gist options
  • Save hiramekun/3556ced882e4ef4edf6d8ce901638d4e to your computer and use it in GitHub Desktop.
Save hiramekun/3556ced882e4ef4edf6d8ce901638d4e to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 097
import java.util.Scanner;
class ColorfulTransceivers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
int d = scanner.nextInt();
if (Math.abs(a - c) <= d){
System.out.print("Yes");
} else if (Math.abs(a-b) <=d && Math.abs(b-c) <= d) {
System.out.print("Yes");
} else{
System.out.print("No");
}
}
}
import java.util.Scanner;
class Exponential {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int X = scanner.nextInt();
int max = 1;
for (int x = X / 2; x > 1; x--) {
for (int y = X / 2; y > 1; y--) {
double pow = Math.pow((double) x, (double) (y));
if (pow > max && pow < X) {
max = ((int) pow);
}
}
}
System.out.print(max);
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
class KthSubstring {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
int K = scanner.nextInt();
List<String> strings = new ArrayList<>();
for (int i = 0; i < s.length(); i++) {
for (int j = 1; j < 6; j++) {
if (i + j > s.length()) {
break;
}
String sub = s.substring(i, i + j);
if (!strings.contains(sub)){
strings.add(sub);
}
}
}
// sort
Collections.sort(strings);
System.out.print(strings.get(K - 1));
}
}
@hiramekun
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment