-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMasai OJ Contest
109 lines (103 loc) · 3.29 KB
/
Masai OJ Contest
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
/*
Masai Sentence Reversal
Description
You are provided with a sentence S, your task is to write a program that reverses the order/sequence in which words are present in the sentence keeping the case of each character preserved (upper case character should remain upper and lower case character is lower case). (Refer to the sample test case for better understanding)
Try using the stack data structure
DO NOT ANY BUILT-IN FUNCTION FOR REVERSING A STRING
Input
Input Format
You are provided with a sentence having one or more than one word.
Constraints
At least one word is present in the string
Output
Output the sentence by reversing the sequence of words
Sample Input 1
A Transformation in education
Sample Output 1
education in Transformation A
Hint
Sample 1 Explanation
The sentence has been reversed in the sense that the sequence in which the words were present in the initial sentence is reversed.
Also, there is no change in the case of characters present in the sentence.
*/
//Enter code here
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
String[] new_str=str.split(" ");
for(int i=new_str.length-1; i>=0; i--){
System.out.print(new_str[i]+" ");
}
}
}
/*
Problem -2
Count Consonant
Description
You are provided a string S. Your task is to write a program that counts the number of consonants (non-vowels characters) present in the string.
Input
Input Format:
First-line contains a string S
Constraints:
Length of String is always lesser than 1000
Output
Output one number which is the count of number of consonants present in the string.
Sample Input 1
masaischool
Sample Output 1
6
*/
//You are provided a string S. Your task is to write a program that counts the number of consonants (non-vowels characters) present in the string.
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int count=0;
for(int i=0; i<str.length(); i++){
if( str.charAt(i)!='a' && str.charAt(i)!='e' && str.charAt(i)!='i' && str.charAt(i)!='o' && str.charAt(i)!='u' && str.charAt(i)!='A' && str.charAt(i)!='E' && str.charAt(i)!='I' && str.charAt(i)!='O' && str.charAt(i)!='U') {
count=count+1;
}
}
System.out.println(count);
}
}
/*
Problem -3
Substring under condition
Description
Given a string S, you need to find the count of all contiguous substrings starting and ending with same character.
Input
Input Format :
First and the only line contains a string S
Constraints:
Length of S <= 1000
Output
Output the count
Sample Input 1
abcab
Sample Output 1
7
*/
//Enter code here
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int count=0;
for(int i=0; i<str.length(); i++){
for(int j=i; j<str.length(); j++){
System.out.println(str.substring(i,j+1)); //print all substring(initial value, final value)
if(str.charAt(i)==str.charAt(j)){
// System.out.println(str.charAt(i)+" "+str.charAt(j));
// System.out.println(str.substring(i,j+1));
count=count+1;
}
}
}
System.out.println(count);
}
}