Algorithm


Problem Link- https://www.spoj.com/problems/IITKWPCA/

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.

  1. 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.
  2. Now reverse all the strings in G. eg. "won", "od", "ti", "won".
  3. 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

 

Code Examples

#1 Code Example with Python Programming

Code - Python Programming

n = int(input())
dp = [0] * 1000002
ans = 1
for i in map(int, input().split(' ')):
    dp[i] = max(dp[i], dp[i - 1] + 1)
    ans = max(ans, dp[i])
print(ans)
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
now do it now
now do it now
I am good boy
am am

Output

x
+
cmd
3
3
4
1
Advertisements

Demonstration


SPOJ Solution-Niceness of the string-Solution in C, C++, Java, Python

Previous
SPOJ Solution - Test Life, the Universe, and Everything - Solution in C, C++, Java, Python