Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1140
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1140
Flowers Flourish from France
by Ines Kereki Uruguay
Timelimit: 1
- Flowers Flourish from France
- Sam Simmonds speaks softly
- Peter pIckEd pePPers
- truly tautograms triumph
Input
Output
For each test case output a single line containing an uppercase 'Y' if the sentence is a tautogram, or an uppercase 'N' otherwise.
Input Sample | Output Sample |
Flowers Flourish from France |
Y |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
typedef struct{
char palavra[21];
} string;
bool isTautograma(string *, unsigned short tam);
int main (void)
{
unsigned short i;
while (true)
{
char frase[2000] = { 0 }, *palavraTmp;
string palavras[100];
scanf(" %[^\n]", frase);
if (strcmp(frase, "*") == 0)
break;
i = 0;
palavraTmp = strtok(frase, " ");
strcpy(palavras[i++].palavra, palavraTmp);
do
{
palavraTmp = strtok('\0', " ");
if (palavraTmp)
strcpy(palavras[i++].palavra, palavraTmp);
} while (palavraTmp);
// Resultado final;
if (isTautograma(palavras, i))
printf("Y\n");
else
printf("N\n");
}
}
bool isTautograma(string *palavras, unsigned short tam)
{
unsigned short i;
for (i = 1; i < tam; i++)
if (tolower(palavras[i].palavra[0]) != tolower(palavras[i - 1].palavra[0]))
return false;
return true;
}
Copy The Code &
Try With Live Editor
Input
Sam Simmonds speaks softly
Peter pIckEd pePPers
truly tautograms triumph
this is NOT a tautogram
*
Output
Y
Y
Y
N
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string s;
char l, u;
bool yes;
while (1)
{
getline(cin,s);
yes=true;
if (s=="*")
break;
if (isupper(s[0]))
{
u=s[0];
l=s[0]-'A'+'a';
}
else if (islower(s[0]))
{
l=s[0];
u=s[0]-'a'+'A';
}
for (int i = 0; i < s.size(); ++i)
{
if (s[i]==' ')
{
if (s[i+1]!=l && s[i+1]!=u)
{
yes=false;
break;
}
}
}
if (yes)
cout << "Y" << endl;
else
cout << "N" << endl;
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Sam Simmonds speaks softly
Peter pIckEd pePPers
truly tautograms triumph
this is NOT a tautogram
*
Output
Y
Y
Y
N
#3 Code Example with Java Programming
Code -
Java Programming
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String l;
String[] w;
while (!(l = in.readLine()).equals("*")) {
w = l.split("\\s");
boolean f = true;
String firstLetter = w[0].substring(0, 1);
for (int i = 1; i < w.length; i++) {
if (!firstLetter.equalsIgnoreCase(w[i].substring(0, 1))) {
f = false;
break;
}
}
out.println(f ? "Y" : "N");
}
out.close();
}
}
Copy The Code &
Try With Live Editor
Input
Sam Simmonds speaks softly
Peter pIckEd pePPers
truly tautograms triumph
this is NOT a tautogram
*
Output
Y
Y
Y
N
#4 Code Example with Python Programming
Code -
Python Programming
while True:
entrada = input()
if entrada == "*":
break
if len(set([k[0].lower() for k in entrada.split()])) == 1:
print("Y")
else:
print("N")
Copy The Code &
Try With Live Editor
Input
Sam Simmonds speaks softly
Peter pIckEd pePPers
truly tautograms triumph
this is NOT a tautogram
*
Output
Y
Y
Y
N