Submit | All submissions | Best solutions | Back to list |
IITKWPCA - Niceness of the string |
The niceness of a string s (s comprises of a-z, A-Z and space characters only) is calculated using steps given below.
- First seperate out the string into continous non zero length string without space. eg. Let us take s = "now do it now". You can break this into four small strings as "now", "do", "it" and "now". Call the set of these small strings to be G.
- Now reverse all the strings in G. eg. "won", "od", "ti", "won".
- Finally you calculate number of distinct strings in you set. in this case answer is 3. as "won", "od" and "ti" are set of distinct strings. Note that "won" comes twice but counted only once.
So you have to find niceness value of a string s.
Note that given string s can contain more than one continous spaces. eg. "now do it now ". Niceness value of this is also same as above given example.
Input
T: number of test cases. (T <= 100)
for next T lines, every line contains one string s (1 <= |s| <= 104)
Output
For every test case, output niceness value of given string s.
Example
Input: 4 now do it now now do it now I am good boy am am Output: 3 3 4 1
Added by: | praveen123 |
Date: | 2013-08-05 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | IITK ACA CSE online judge |
hide comments
|
||||||||
2015-09-23 12:14:14 ANIKET
My 500th submission AC for this one 3 lines in python.... |
||||||||
2015-09-17 07:14:24 BadeMeow
string size 10^4 =>test case can have a single string of length 10^4 cost me 2 SIGSEGVs!! |
||||||||
2015-07-16 16:19:18 Alaf Azam Khan
First problem in python |
||||||||
2015-07-01 07:13:52 Akshat Mathur
Did using STL :-) |
||||||||
2015-06-28 10:21:49 kp
No need to reverse the words -_- |
||||||||
2015-06-14 14:07:50 Piyush Kumar
Too easy with python. |
||||||||
2015-06-05 11:20:07 Ankush
An ideal question for python lovers like me :P |
||||||||
2015-06-02 18:37:13 :.Mohib.:
3 lines in python :) |
||||||||
2015-01-07 22:20:14 Sahil Dua
2 lines in Python :P |
||||||||
2015-01-07 16:05:01 Anubhav Gupta
Java gives TLE ;( |