Skip to content

Commit d2f28aa

Browse files
authored
Add files via upload
1 parent b11a73a commit d2f28aa

7 files changed

+2124
-76
lines changed

Hard/AlphabetRunEncryption.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Main {
5+
6+
static char SAG = 'R';
7+
static char SOL = 'L';
8+
static char IKIZ = 'S';
9+
static char YOK = 'N';
10+
static String HEPSI = "RLSN";
11+
12+
public static String StringChallenge(String str) {
13+
// code goes here
14+
15+
StringBuilder result = new StringBuilder("");
16+
char [] c = str.toCharArray();
17+
18+
for ( int i =c.length-1 ; i>=0 ; i--){
19+
20+
String parca = yeniParca(str,i);
21+
String sifre = kod(parca);
22+
23+
if (i != c.length -1 && result.charAt(0) == sifre.charAt(sifre.length()-1)) {
24+
result = result.insert(0,sifre.substring(0,sifre.length()-1));
25+
26+
}else{
27+
28+
result = result.insert(0,sifre);
29+
30+
}
31+
i-=parca.length()-1;
32+
33+
}
34+
35+
return result.toString();
36+
}
37+
38+
39+
public static String yeniParca (String str,int s){
40+
41+
StringBuilder parca = new StringBuilder("");
42+
boolean artan =str.charAt(s) < str.charAt(s-1);
43+
44+
for ( int i = s ; i>=0; i--){
45+
46+
char c = str.charAt(i);
47+
48+
if (HEPSI.indexOf(c) != -1 && parca.length()==0){
49+
if (c==SAG || c==SOL || c== YOK){
50+
return str.substring(s-1,s+1);
51+
}else if (c==IKIZ){
52+
return str.substring(s-2,s+1);
53+
}
54+
}
55+
56+
if (i==s){
57+
parca = parca.append(c);
58+
continue;
59+
}
60+
61+
char prevC = str.charAt(i+1);
62+
if (artan && c == (prevC +1) ){
63+
parca = parca.insert(0,c);
64+
65+
} else if (!artan && c== (prevC-1)) {
66+
parca = parca.insert(0,c);
67+
68+
}else{
69+
break;
70+
}
71+
}
72+
return parca.toString();
73+
74+
}
75+
76+
public static String kod (String parca){
77+
78+
if (parca.indexOf(SAG) != -1){
79+
char c = parca.charAt(0);
80+
return String.valueOf((char)(c-1))+String.valueOf((char)(c+1));
81+
} else if (parca.indexOf(SOL) != -1){
82+
char c = parca.charAt(0);
83+
return String.valueOf((char)(c+1)) + String.valueOf((char)(c-1));
84+
} else if ( parca.indexOf(IKIZ) != -1){
85+
return parca.substring(0,2);
86+
}else if (parca.indexOf(YOK) != -1){
87+
char c = parca.charAt(0);
88+
return String.valueOf(c) + String.valueOf(c);
89+
90+
}
91+
92+
93+
char bas = parca.charAt(0);
94+
char son = parca.charAt(parca.length()-1);
95+
96+
if (bas>son){
97+
return String.valueOf((char)(bas+1)) + String.valueOf((char)(son-1));
98+
99+
}
100+
101+
return String.valueOf((char)(bas-1)) + String.valueOf((char)(son+1));
102+
103+
}
104+
105+
public static void main (String[] args) {
106+
// keep this function call here
107+
Scanner s = new Scanner(System.in);
108+
System.out.print(StringChallenge(s.nextLine()));
109+
}
110+
111+
}

Hard/ArrayRotation.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Main {
5+
6+
public static boolean StringChallenge(String str) {
7+
8+
String[] arr= str.split(" ");
9+
10+
for(int i=0; i<arr.length; i++){
11+
12+
String s = arr[i].replaceAll("[a-zA-Z]","");
13+
14+
if(arr[i].contains(s)){
15+
return false;
16+
}
17+
18+
boolean a= ( s.chars().distinct().count()==3 ? true :false ); //regex yordu.
19+
20+
if(a==false){
21+
return false;
22+
}
23+
}
24+
25+
return true;
26+
}
27+
28+
public static void main (String[] args) {
29+
// keep this function call here
30+
Scanner s = new Scanner(System.in);
31+
System.out.print(StringChallenge(s.nextLine()));
32+
}
33+
34+
}

Hard/NumberEncoding.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Main {
5+
6+
public static String StringChallenge(String str) {
7+
// code goes here
8+
String result="";
9+
str.toLowerCase();
10+
for(int i=0;i<str.length();i++){
11+
if(Character.isLetter(str.charAt(i))){
12+
result+=str.charAt(i)-97+1;
13+
}
14+
else{
15+
result+=str.charAt(i);
16+
}
17+
18+
}
19+
20+
return result;
21+
}
22+
23+
public static void main (String[] args) {
24+
// keep this function call here
25+
Scanner s = new Scanner(System.in);
26+
System.out.print(StringChallenge(s.nextLine()));
27+
}
28+
29+
}

Hard/RomanNumeralReduction.java

Lines changed: 26 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,46 @@
1-
import java.util.*;
1+
import java.util.*;
22
import java.io.*;
33

4-
class Main {
5-
static String RomanNumeralReduction(String str){
6-
return reduce(calculate(str));
7-
}
8-
9-
static String reduce(int num) { // 800 = DCCC, 899 = DCCCXCIX, 900 = CM, 999 = CMXCIX
10-
String mResult = "";
11-
int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
12-
String[] letters = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
13-
int i = 0;
14-
while (num > 0) {
15-
while (num >= values[i]) {
16-
mResult += letters[i];
17-
num -= values[i];
18-
}
19-
i++;
20-
}
21-
return mResult;
22-
}
23-
24-
static int calculate(String roman){
25-
int sum = 0;
26-
for (int i = 0; i < roman.length(); i++) {
27-
if (i + 1 < roman.length() && value(roman.charAt(i)) < value(roman.charAt(i + 1)))
28-
sum -= value(roman.charAt(i));
29-
else
30-
sum += value(roman.charAt(i));
31-
}
32-
return sum;
33-
}
34-
35-
static int value(char c){
36-
switch (c){
37-
case 'I': return 1;
38-
case 'V': return 5;
39-
case 'X': return 10;
40-
case 'L': return 50;
41-
case 'C': return 100;
42-
case 'D': return 500;
43-
case 'M': return 1000;
44-
default: return 0;
45-
}
46-
}
47-
public static void main(String[] args) {
48-
Scanner s = new Scanner(System.in);
49-
System.out.println(RomanNumeralReduction(s.nextLine())););
50-
}
51-
}
52-
EmreDenizz09.06.2022
534
class Main {
545

55-
public static String RomanNumeralReduction(String str) {
56-
char[] arr = str.toCharArray();
57-
int[] nums = {1,5,10,50,100,500,1000};
58-
char[] rom = {'I','V','X','L','C','D','M'};
59-
int num = 0;
60-
int count = 0;
6+
public static String StringChallenge(String str) {
7+
char []arr = str.toCharArray();
8+
int []nums= {1,5,10,50,100,500,1000};
9+
char []rom={'I','V','X','L','C','D','M'};
10+
int num=0;
11+
int count=0;
6112
String ret = "";
6213
String exit = "";
6314

64-
for(int i = 0; i < arr.length; i++){
65-
for(int j = 0; j < rom.length; j++){
66-
if(arr[i] == rom[j]){
67-
num = num + Integer.valueOf(nums[j]);
15+
for(int i=0;i<arr.length;i++){
16+
for(int j=0;j<rom.length;j++){
17+
if(arr[i]==rom[j]){
18+
num=num+Integer.valueOf(nums[j]);
6819
}
6920
}
7021
}
71-
for (int z = nums.length - 1; z >= 0; z-- ){
22+
for(int z = nums.length-1;z>=0;z--){
7223
count = num / Integer.valueOf(nums[z]);
73-
num = num % Integer.valueOf(nums[z]);
74-
if(count > 0){
75-
ret = Printer(count,String.valueOf(rom[z]));
76-
exit = exit + ret;
24+
num=num%Integer.valueOf(nums[z]);
25+
if(count >0){
26+
ret = Print(count, String.valueOf(rom[z]));
27+
exit = exit+ret;
7728
}
78-
}
79-
return exit;
29+
}return exit;
8030
}
81-
82-
public static String Printer(int sub, String word){
83-
String back = "";
31+
public static String Print(int sub, String word){
32+
String back = "";
33+
for(int i =0; i<sub; i++){
34+
back = back + word;
35+
}return back;
36+
}
8437

85-
for(int i = 0; i < sub; i++){
86-
back = back + word;
87-
}
88-
return back;
89-
}
38+
39+
9040
public static void main (String[] args) {
9141
// keep this function call here
9242
Scanner s = new Scanner(System.in);
93-
System.out.print(RomanNumeralReduction(s.nextLine()));
43+
System.out.print(StringChallenge(s.nextLine()));
9444
}
9545

9646
}

Hard/SquareFigures.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Main {
5+
6+
public static String StringChallenge(String[] strArr) {
7+
// Abdullah Tas
8+
9+
int point = 0 , comma = 0;
10+
11+
for ( int i = 0; i < strArr[0].length(); i++){
12+
char letter = strArr[0].charAt(i);
13+
if(letter=='.') point++;
14+
if (letter==',') comma++;
15+
if(point>1) return "false";
16+
if(Character.isAlphabetic(letter)) return "false";
17+
}
18+
19+
if (comma!=0){
20+
21+
String [] number = strArr[0].split(",");
22+
// 1,453,44,443.03
23+
for ( int i = 1 ; i<number.length-1 ; i++){
24+
if (number[i].length()!=3) return "false";
25+
}
26+
//443.03
27+
if(point!=0){
28+
String last = number[number.length-1].substring(0,number[number.length-1].indexOf(".")); //(0,3)
29+
if(last.length() != 3 ) return "false";
30+
}
31+
if(number[0].length()>3) return "false";
32+
33+
}else{ // 10.00
34+
35+
if(point != 0){
36+
String last = strArr[0].substring(0,strArr[0].indexOf('.'));
37+
if ( last.length() > 3 ) return "false";
38+
}else{
39+
// 1243
40+
if (strArr[0].length() > 3) return "false";
41+
}
42+
43+
44+
}
45+
46+
47+
return "true";
48+
}
49+
50+
public static void main (String[] args) {
51+
// keep this function call here
52+
Scanner s = new Scanner(System.in);
53+
System.out.print(StringChallenge(s.nextLine()));
54+
}
55+
56+
}

0 commit comments

Comments
 (0)