Ratetod文字fexir


14

我在这本怪异的文字中写上了vewols似乎被贬低的地方:

我的文字写得不好。一些疯子用元音命令演奏。请解决我!

因此,我需要一个可以对vewols(以及看起来像是“ y”字母)进行评级的实用程序,以便文本是raadeble agian。

Ouy可以选择ouyr chieco privedod ouy meka的肺部cempleto pragrom(因此不仅是finctoun)。语法可以是未经处理的字段,文本格式的内容或cammond leni。uutpot mya olsa vyra,饰演ouy leki。

cuerso的我将为yna pragrom uutpitong写烂文字。pragrom中没有任何vulea,这使您无法理解。但是如果您愿意的话,您可以在率文本中使用ouyr cemmonts和qeistouns。


澄清说明

  • 您的程序仅需要处理ASCII文本。
  • 出于这个问题的目的,以下字符是元音: aeiouy
  • 每个单词中的元音位置应旋转。在确定什么才是单词时有一定的灵活性:最低要求是用空格分隔的两个字符在不同的单词中,并且a-zA-Z仅用字母字符分隔的两个字母在同一单词中。
  • 所需的旋转方向应从以下测试案例中得出。

测试用例

输入:I'm a badly written text. Some lunatic guy played with the order of vowels. Please fix me !
输出:I'm a bydla wrettin text. Semo lanituc gyu plyead with the erdor of vewols. Plaese fix me !

输入:AeiOuy
输出:EioUya

输入:Hyphenated-word
输出:Hephanetyd-wordHephanetod-wyrd


1
定义元音
彼得·泰勒

5
我leki“保留”在此centoxt。
霍华德

2
这个问题是故意不透明的。给出了几种可能的定义(除其他外,只有10个代码点对应aeiouAEIOU于ASCII /基本拉丁语;这些代码点加上基本拉丁语和Latin-1增补中的所有其他代码点,这些基本点与变音符号组合在一起) ,问题应该明确。
彼得·泰勒

1
@PeterTaylor我采用ASCII
John Dvorak

8
游戏不应该是猜测问题。请参阅常见问题解答:“ 此站点上的所有问题,无论是编程难题还是代码高尔夫球,都应…明确说明什么构成正确的提交。”
彼得·泰勒

Answers:


6

GolfScript,68 67 57个字符

" "/{..+{95&"AEIOUY"?)}:C,1>\{.C!!{96&\(31&@|}*}%\;}%" "*

输入必须在STD​​IN上给出。示例(在线):

> You!!! I'm a badly written text. Some lunatic guy played with the order of vowels. Please fix me !
Ouy!!! I'm a bydla wrettin text. Semo lanituc gyu plyead with the erdor of vewols. Plaese fix me !

5

Ruby,91个 90个字符

$><<gets.gsub(/\S+/){|x|x.gsub(r=/[aeiouy]/i){|y|z=$'[r]||x[r];y>?Z?z.downcase: z.upcase}}

Coffeescript,148个字符

alert prompt().replace /\S+/g,(x)->x.replace r=/[aeiouy](?=(.*))/gi,(y,z)->((t=z.match r)&&t[0]||x.match(r)[0])[['toLow','toUpp'][y>'Z']+'erCase']()

没有ussimtoans,除了“ hol-cerract”是一个单词,而不是我的sulitoon。

测试:

> To test this program, simply enter a long sentence that appears half-broken
  To test this pragrom, sympli enter a long sentence that eppaars holf-brekan

> No MaTtEr HoW mUcH cAsE yOu uSe, It WoRkS
  No MeTtAr HoW mUcH cEsA oUy eSu, It WoRkS

关于Ruby代码:1)通过使用$&代替第二个gsub()块的y参数来保留2个字符;2)通过使用?Z来代替1个字符'Z'
manatwork 2013年

@manatwork $&无法使用,因为在我使用它之前已对其进行了更改。z=$'[r]改变它。关于?Z-谢谢,我完全忘记了这种语法。
John Dvorak 2013年

哎呀 不知道我昨天如何对其进行测试,因此似乎可以正常工作……
manatwork 2013年

2

Haskell,159个字符

最终并没有我希望的那么短,但是我还是决定将其发布:

import Data.Char
f s=let(v,t)=foldr g(v,[])s in t
g x(v,t)=last$(v,x:t):[(x,c v:t)|c<-[toUpper,toLower],x`elem`map c"AEIOUY"]
main=interact$unwords.map f.words

非高尔夫版本:

import Data.Char

rotateVowels :: String -> String
rotateVowels word = result
  where (vowel, result) = foldr step (vowel, []) word
        step ch (vowel, rest)
          | ch `elem` "AEIOUY" = (ch, toUpper vowel : rest)
          | ch `elem` "aeiouy" = (ch, toLower vowel : rest)
          | otherwise          = (vowel, ch : rest)

main = interact $ unwords . map rotateVowels . words

这是一个很好的例子,说明懒惰的评估如何让您做一些绝妙的技巧。在中rotateVowels,每次找到新的元音时,它都会传到左边,而用右边的元音替换。折叠输出的这一部分作为输入被反馈,以便最左边的元音成为最右边的元音的替代。

(vowel, result) = foldr step (vowel, []) word
 ^^^^^                        ^^^^^
 this part of the output      is part of the input

1

Python 2,172个字节

for w in input().split():p=[];q=list(w);z=filter(lambda c:c in'aeiouyAEIOUY',q);x=z[1:]+z[:1];print''.join(y in z and[str.upper,str.lower][y>'Z'](x.pop(0))or y for y in q),

在线尝试!


@KevinCruijssen修复了它
ovs '17
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.