-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathString problems
129 lines (114 loc) · 3.31 KB
/
String problems
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception // input heey
{ //output heeeey
Scanner sc = new Scanner(System.in);
String s = sc.next();
// System.out.print(s.replace("e","ee"));
//int count = s.length() -2;
int count=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='e'){
count++;
}
}
String arr ="h";
for(int i=0;i<2*count;i++){
arr += "e";
}
arr += "y";
System.out.println(arr);
}
}
/// ATORI
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in); // input Kimo-Manas-Petter
String s1 = sc.next(); //output KMP
String ret ="";
ret += s1.charAt(0);
for(int i=0;i<s1.length();i++){
if(s1.charAt(i)=='-'){
ret += s1.charAt(i+1);
}
}
System.out.println(ret);
}
}
Shuffle String
Given a string s and an integer array indices of the same length.
The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.
Print the shuffled string.
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in); // input 8
int n = sc.nextInt(); // leetcode
String s1 =sc.next(); // 4 5 6 7 0 2 1 3
int num[] = new int[n]; // codeleet
for(int i=0;i<n;i++){
num[i] = sc.nextInt();
}
char arr[]=new char[n];
for(int i=0;i<s1.length();i++){
char ch = s1.charAt(i);
int target = num[i];
arr[target] = ch;
}
System.out.println(arr);
}
}
//CHECK WHEATHER A STRING IS PALINDROME OR NOT
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
int start =0;
int end = s.length()-1;
while(start<end){
if(s.charAt(start)!=s.charAt(end)){
System.out.println("string is not palindrome");
return;
}
start++;
end--;
}
System.out.println("string is palindrome");
}
}
/* Last index of One
Given a string S consisting only 0s and 1s, find the last index of the 1 present in it. */
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
int index = -1;
for (int i = 0;i<s.length();i++)
{
if(s.charAt(i) =='1')
{
index = i;
}
}
System.out.print(index);
}
}