且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从英语到猪拉丁语

更新时间:2023-02-26 11:51:44

首先,把句子分成单词,通过查找空格,或使用 strtok 函数



将每个单词推入数组



然后遍历那个数组,'把'字化,把结果推到同一个数组,或另一个数组



然后走过修改后的阵列,打印每个成员后面有一个空格



数组是令人讨厌的,它们必须被预先设定(除非你正在做它们是动态的)和字符串数组甚至更令人讨厌



你可能有更多的运气使用 std :: vector [ ^ ]的std::string [ ^ ] s
first, take the sentence and split it up into words, either by looking for spaces, or using the strtok function

Push each of those words into an array

Then walk through that array, 'pig'ify the word, and shove the result into the same array, or another one

Then walk thru the modified array printing each member with a space after it

array's are irksome, they have to be presized (unless you're doing them dynamically) and arrays of strings are more even irksome

you might have more luck using std::vector[^]s of std::string[^]s


我实际上在其中一个(大约20年前)在命令行界面上工作。



有许多猪拉丁方言。通用性是如何在第一个元音之前递送任意数量的辅音?



我解决了这个问题,处理了从无用到心理的任何事情(及以后)。



创建一个递归函数,它可以完成两件事:

如果有一个辅音,请将它移到最后字符串和调用本身。

如果有元音,请附加方言的结尾并启动返回链。



提示(警告):in案例输入是意外的所有辅音,你必须防止失控的递归。这并不难,但我把它留给你的想象力。当然,您需要将文本输入转换为单个单词。







注意:Piglatin to English是一个更难的问题。
I actually made one of these (about 20 years ago) working on a command-line interface.

There are many dialects of pig-latin. The commonality is "how do you hand an arbitrary number of consonants preceding the first vowel?"

I solved this in a manner which handled anything from 'useless through psychological' (and beyond).

Create a recursive function that does two things:
If there's a consonant, move it to the end of the string and call itself.
If there's a vowel, append your dialect's ending and start the return chain.

Hint (warning): in case input is accidentally all consonants you have to prevent a runaway recursion. That's not difficult, but I leave it to your imagination. You will, of course, need to convert your text input into individual words.



Note: Piglatin to English is a more difficult problem.