pex2_6.cpp

来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 49 行

CPP
49
字号
#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 + =
减小字号Ctrl + -
显示快捷键?