Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Problem : Valid Segments 2

Consider text comprised of sentences and sentences comprised of words. Words in a sentence will be space delimited. Text will comprise of two types of words, viz. alpha words and beta words. Alpha words are denoted in the input. All words in the text which are non-alpha words are beta words. Task is to find out the number of valid segment with number of beta words in the given range [lb, ub].

A segment is said to be valid if
It contains all the K-strings
It should start and end with any one of the K-strings


Input Format:

First line contains the text. Next line contains K, lb, ub. Next K lines consist of alpha words in the text.

Note:

String comparison should be case insensitive.
String comparison should be based only on words comprised of alphabets. Non-alphabet characters such as Full Stop ("."), Exclamation Marks ("!") etc. are called as Stop words. Stop words must be removed from sentences before comparison.
If more than one segment starts with the same index (i.e. position of the word in the text), then consider the shortest segment. In other words, segments should begin from unique indexes.


Output Format:

Print the number of valid segments with number of beta words in the given range [lb, ub].

Constraints:
1<= total number of words in the text <= 30,000

1<= length of alpha and beta words <= 500

1<=K<=total number of alpha words

1<=lb<=ub<=total number of beta words


Sample Input and Output

SNo. Input Output
1
The European market crashes on Mondays. Crashes in the European market are quite common.
2 3 4
European
Crashes


1



Explanation:

Valid segments are:
European market crashes
crashes on Mondays. Crashes in the European
Crashes in the European
Posted
Comments
[no name] 28-Aug-14 4:15am    
Yes.
nv3 28-Aug-14 4:51am    
Would I code something for someone who doesn't even care to spell his question correctly: No.

1 solution

Yes. Yes someone could. Probably, your teacher, and the rest of your class just for starters.

But...it you mean "Will someone code for thid to save me having to" then no. No, we won't.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
Vignesh U 28-Aug-14 4:24am    
hmmm thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900