当前位置:网站首页>7-2 h0107. Pig-Latin

7-2 h0107. Pig-Latin

2022-06-11 17:38:00 Tomatoes_ Menon

You have determined PGP Encryption is not powerful enough for your email . You have decided to convert clear text letters to Pig Latin, And then use PGP Encryption to complement it .

Input format :

You will write a program , The program will receive any number of text lines and Pig Latin Output . Each line of text will contain one or more words .“ word ” Is defined as a sequence of consecutive letters ( Capital and / Or lowercase ). Words should be converted to according to the following rules Pig Latin( Non words should be exactly the same as what appears in the input ):

  1. A word that begins with a vowel (a、e、i、o or u, And their upper case versions ) Only strings should be appended `` ay ''( Exclude Quotes ). for example ,“ apple ” Turned into “ appleay ”.

  2. Words that begin with consonants ( except A、a、E、e、I、i、O、o、U or u Any letter other than ) The first consonant should be deleted and appended to the end of the word , Then attach ay'' It's also . for example ,hello'' become `` ellohay ''.

  3. Do not change the case of any letters .

Output format :

Enter... For each group , In a line with Pig Latin Output .

sample input :

This is the input.

sample output :

hisTay isay hetay inputay.
#include<stdio.h>
int isletter(char a)
{
	if (a >= 65 && a <= 90)
		return 1;
	else if (a >= 97 && a <= 122)
		return 1;
	return 0;
}
int isvowel(char c)
{
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
	{
		return 1;
	}
	return 0;
}
char b[1024], t;
int main()
{
	char a;
	int i;
	while (scanf("%c", &a)!=EOF)
	{
		if (isletter(a) == 1)
		{
			b[t++] = a;
		}
		else
		{
			if (t == 0) {
				printf("%c", a);
				continue;
			}
			if (isvowel(b[0]) == 1) {
				for (i = 0; i < t; ++i) {
					printf("%c", b[i]);
				}
				printf("ay%c", a);
			}
			else {
				for (i = 1; i < t; ++i) {
					printf("%c", b[i]);
				}
				printf("%cay%c", b[0], a);
			}
			t = 0;
		}
	}
	return 0;
}

 

原网站

版权声明
本文为[Tomatoes_ Menon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111717105329.html