Algorithm


problem link- https://www.spoj.com/problems/MFLAR10/

MFLAR10 - Flowers Flourish from France

 

Fiona has always loved poetry, and recently she discovered a fascinating poetical form. Tautograms are a special case alliteration, which is the occurrence of the same letter at the beginning of adjacent words. In particular, a sentence is a tautogram if all of its words start with the same letter. 

For instance, the following sentences are tautograms:

  • Flowers Flourish from France
  • Sam Simmonds speaks softly
  • Peter pIckEd pePPers
  • truly tautograms triumph

Fiona wants to dazzle her boyfriend with a romantic letter full of this kind of sentences. Please help Fiona to check if each sentence she wrote down is a tautogram or not.

Input

Each test case is given in a single line that contains a sentence. A sentence consists of a sequence of at most 50 words separated by single spaces. A word is a sequence of at most 20 contiguous uppercase and lowercase letters from the English alphabet. A word contains at least one letter and a sentence contains at least one word.

The last test case is followed by a line containing only a single character ‘*’ (asterisk).

Output

For each test case output a single line containing an uppercase ‘Y’ if the sentence is a tautogram, or an uppercase ‘N’ otherwise.

Example

Sample input:
Flowers Flourish from France
Sam Simmonds speaks softly
Peter pIckEd pePPers
truly tautograms triumph
this is NOT a tautogram
*

Sample Output:
Y
Y
Y
Y
N

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <map>

using namespace std;

int main(){
	while(true){
		string s;
		bool ans=true;
		getline(cin,s);
		if(s[0]=='*')
			break;
		int sppos=-1;
		char prevchar=tolower(s[0]);
		for(int i=1;i<s.length();i++){
			if(s[i]==' '){
				sppos=i;
			}
			if(i==(sppos+1)){
				if(prevchar!=tolower(s[i])){
					//cout<<prevchar<<" "<<i<<""<<sppos<<" ";
					ans=false;
					break;
				}
			}
		}
		if (ans)
			printf("Y\n");
		else
			printf("N\n");
	}
	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
Flowers Flourish from France
Sam Simmonds speaks softly
Peter pIckEd pePPers
truly tautograms triumph
this is NOT a tautogram
*

Output

x
+
cmd
Y
Y
Y
Y
N
Advertisements

Demonstration


SPOJ Solution-Flowers Flourish from France-Solution in C, C++, Java, Python

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