⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pex2_6.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 CPP
字号:
#include <iostream.h>
#include <string.h>
#include <ctype.h>

// determine if ch is a vowel
int isvowel(char ch)
{
	char lower= tolower(ch);
	
	if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
		return 1;
	else
		return 0;
} 

void main(void)
{
	char word[20];
	// piglatin equiv. of word. endconsonant used to append
	// 1st char of word and "ay" when word begins with consonant
	char piglatin[22], endconsonant[4] = "xay";

	// read words until end of file. no attempt
	// is made to preserve word spacing in the output
	while(cin >> word)
	{
		if (isvowel(word[0]))
		{
			strcpy(piglatin,word);
			strcat(piglatin,"ay");
		}
		else
		{
			strcpy(piglatin, &word[1]);
			endconsonant[0] = word[0];
			strcat(piglatin,endconsonant);
		}
		cout << piglatin << " ";
	}
	cout << endl;
}

/*
<Run>

This is a sentence with pig latin
hisTay isay aay entencesay ithway igpay atinlay
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -