A good string is a string or a substring that starts with the character "g" and ends with the character "d". For a given string, write a program to find the number of "good substrings" of a given string. Note - A substring of a string is a contiguous subsequence of that string. The list of all non-empty substrings of the string "apple" would be "apple", "appl", "pple", "app", "ppl", "ple", "ap", "pp", "pl", "le", "a", "p", "p", "T", and "e" There will be multiple test cases running so the Input and Output should match exactly as provided. The base output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables. Input Format The first line contains the string S. Sample Input godk - denotes S Constraints. 1 <= len|S| <= 100 Output Format The output contains a single integer denoting the number of good substrings of the given string. Sample Output

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question
A good string is a string or a substring that starts with the character "g" and ends with the character "d".
For a given string, write a program to find the number of "good substrings" of a given string.
Note
- A substring of a string is a contiguous subsequence of that string.
The list of all non-empty substrings of the string "apple" would be "apple", "appl", "pple", "app", "ppl", "ple", "ap", "pp", "pl", "le", "a", "p", "p", "I", and "e"
There will be multiple test cases running so the Input and Output should match exactly as provided.
The base output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables.
Input Format
The first line contains the string S.
Sample Input
godk - denotes S
Constraints
1 <= len|S| <= 100
Output Format
The output contains a single integer denoting the number of good substrings of the given string.
Sample Output
1
Explanation
In the given string, only one substring "god" is good.
Hence, the answer is 1
Transcribed Image Text:A good string is a string or a substring that starts with the character "g" and ends with the character "d". For a given string, write a program to find the number of "good substrings" of a given string. Note - A substring of a string is a contiguous subsequence of that string. The list of all non-empty substrings of the string "apple" would be "apple", "appl", "pple", "app", "ppl", "ple", "ap", "pp", "pl", "le", "a", "p", "p", "I", and "e" There will be multiple test cases running so the Input and Output should match exactly as provided. The base output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables. Input Format The first line contains the string S. Sample Input godk - denotes S Constraints 1 <= len|S| <= 100 Output Format The output contains a single integer denoting the number of good substrings of the given string. Sample Output 1 Explanation In the given string, only one substring "god" is good. Hence, the answer is 1
1- function solution(str) {
2
5678AWN
3
4 }
6 function main() {
9
10
12-
13
Addr
15
16
17
19
// write your code here
return 0;
}
var readline = require("readline");
var rl = readline.createInterface (process. stdin, process.stdout);
rl.prompt();
let args = []
rl.on("line", (input) => {
});
args.push(input)
if(args.length = 1) {
main();
console.log(solution (args[0]));
rl.close();
I
Transcribed Image Text:1- function solution(str) { 2 5678AWN 3 4 } 6 function main() { 9 10 12- 13 Addr 15 16 17 19 // write your code here return 0; } var readline = require("readline"); var rl = readline.createInterface (process. stdin, process.stdout); rl.prompt(); let args = [] rl.on("line", (input) => { }); args.push(input) if(args.length = 1) { main(); console.log(solution (args[0])); rl.close(); I
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT