Q1) Terrible Chandu
---------------------------------------------------------------------------------
Chandu is a bad student. Once his teacher asked him to print the reverse of a given string. He took three hours to solve it. The teacher got agitated at Chandu and asked you the same question. Can you solve it?
Input:
The first line contains an integer T, denoting the number of test cases.
Each test case contains a string S, comprising of only lower case letters.
The first line contains an integer T, denoting the number of test cases.
Each test case contains a string S, comprising of only lower case letters.
Output:
For each test case, print the reverse of the string S.
For each test case, print the reverse of the string S.
Constraints:
1 <= T <= 10
1 <= |S| <= 30
Sample Input Sample Output
2
ab ba
aba aba
Answer
----------
----------
import java.io.InputStreamReader;
class TestClass {
public static void main(String args[] ) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
for (int i = 0; i < N; i++) {
String s=br.readLine();
String r="";
for(int j=s.length()-1;j>=0;j--){
r=r+s.charAt(j);
}
System.out.println(r);
}
}
}
Q2) Chandu and Consecutive Letters
---------------------------------------------------------------------------------
Chandu is very fond of strings. (Or so he thinks!) But, he does not like strings which have same consecutive letters. No one has any idea why it is so. He calls these strings as Bad strings. So, Good strings are the strings which do not have same consecutive letters. Now, the problem is quite simple. Given a string S, you need to convert it into a Good String.
You simply need to perform one operation - if there are two same consecutive letters, delete one of them.
Input:
The first line contains an integer T, denoting the number of test cases.
Each test case consists of a string S, which consists of only lower case letters.
The first line contains an integer T, denoting the number of test cases.
Each test case consists of a string S, which consists of only lower case letters.
Output:
For each test case, print the answer to the given problem.
For each test case, print the answer to the given problem.
Constraints:
1 <= T <= 10
1 <= |S| <= 30
1 <= T <= 10
1 <= |S| <= 30
Sample Input Sample Output
3
abb ab
aaab ab
ababa ababa
Answer
----------
import java.io.BufferedReader;
import java.io.InputStreamReader;
class TestClass {
public static void main(String args[] ) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
for (int i = 0; i < N; i++) {
String s= br.readLine();
String r="";
int x;
for(int j=0;j<s.length();j=x){
x=j;
while(++x<s.length() && s.charAt(x)==s.charAt(j));
r=r+s.charAt(j);
}
System.out.println(r);
}
}
}
Really nice topics you had discussed above. I am much impressed. Thank you for providing this nice information here
ReplyDeleteSoftware Testing Company
Mobile Game Testing
Gameplay Testing
Switch Game Testing
Nice
ReplyDeleteThis is very helpful post for me. Hope you like my post too.. visit once
ReplyDeletecoding query
Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
ReplyDeleteSelenium Training in Chennai | Certification | Online Training Course | Selenium Training in Bangalore | Certification | Online Training Course | Selenium Training in Hyderabad | Certification | Online Training Course | Selenium Training in Coimbatore | Certification | Online Training Course | Selenium Training in Online | Certification | Online Training Course