在西班牙语中,“or”一词表示为“o”,但后面字母以“o”或“ho”开头的情况除外(包括“ó”或“hó”等重音形式)。如果数字以“o”开头,也遵循此规则888或者完全111111,因为所有以888西班牙语中以“och”开头,如ocho (8)、ochenta (80)、ochocientos (800) 等,因此这些词以“o”开头,数字111111西班牙语中的“ once ”以“o”开头。西班牙语中的“H”不发音,因此在以“Ho”开头的单词前使用“u”,无论有无重音。
例子:
我想吃 3 或 4 个煎饼。
我有两个选择:
来吧 34 磅煎饼,Octavio 或者 Manuel?
如何购买 78 块薄饼,Manuel 或 Octavio?
任务
您的任务是根据字符串(见下文)选择“o”或“u”,该字符串可能包含字母数字字符,包括以下字符:(ÁÉÍÓÚáéíóúüÑñ
如果您的(编程)语言不支持这些字符,您可以忽略这些字符,而是使用您选择的其他字符(必须是 13 个字符长,包括 2 个表示“o”的字符,但如果您的语言支持,这些字符是必需的))以最短的方式,因为这是。即使字符串中的字符不是字符串的第一个字符,它们也可以大写。字符串不能以双“h”开头,也不能同时包含数字和字母。
如果满足以下条件之一,则输出“o”:
-
该字符串是一个数字,但它不以888,或者不是数字111111
-
字符串不以“o”、“ó”、“O”或“Ó”开头
-
该字符串不是以“ho”、“Ho”、“hO”、“HO”、“hó”、“Hó”、“hÓ”或“HÓ”开头(抱歉)。
如果不符合上述标准,则输出“u”。
测试用例
alejandro => o
óleo => u
oreja => u
Hórrido => u
833 => u
8 => u
11 => u
1 => o
111 => o
6 => o
mal => o
horno => u
hOra => u
Héroe => o
Chocolate => o
WordInEnglish => o
OSO => u
Paro => o
o => u
u => o
O => u
U => o
Ho => u
Hu => o
Hueso => o
Humo => o
Húmedo => o
\endgroup
6
14 个解决方案
14
JavaScript (ES6),37 字节
s=>"ou"[+/^h?[oó]|^11$|^8/i.test(s)]
\endgroup
|
Google 表格,49 字节
=if(regexmatch(A1,"(?i)^h?[oó]|^11$|^8"),"u","o")
将字符串放入单元格中A1
,将公式放入B1
。期望数据是问题中指定的文本字符串(格式 > 数字 > 纯文本)。使用。
\endgroup
|
字节
Mi`^11$|^8|^h?[oó]
T`d`\ou
链接包括删除后缀的测试套件, => [ou]
以允许将测试用例用作输入。说明:@Arnauld 的 JavaScript 答案的移植。
Mi`^11$|^8|^h?[oó]
计算输入中模式出现的次数。
T`d`\ou
将其索引到字符串中ou
。(o
在音译模式下很神奇,因此需要将其引用为文字。d
也很神奇,比写作短一个字节01
。)
\endgroup
|
i
,24字节
^(11$|8|h?[oó]).*
.+
u
o
如果在最开始(^
)我们发现以下任何一项:
- “11”后跟结尾 (
$
) - “8”
- 可选的 (
?
) “h” 后跟“o”或“ó”
.+
然后我们用“u”替换它和它后面的所有内容( )。
其他所有内容(.+
)我们均用“o”替换。
\endgroup
|
,66 字节
lambda s:'ou'[s.strip('hH')[:1]in[*'oóOÓ']or'8'==s[:1]or'11'==s]
/^[hH]*$/g
如果可以输出字符串匹配'u'
而不是'o'
,则可以删除列表解包(-3 个字节)。
\endgroup
|
,47 字节
\(s)`if`(grepl("^h?[oó]|^11$|^8",s,T),"u","o")
的端口。
\endgroup
|
,24字节
§uo∧⁻N¹¹⬤8oó⬤θ⌕↧θ⁺…hμι
链接为代码的详细版本。说明:
N Input as a number (zero if not)
⁻ Subtract
¹¹ Literal integer `11`
∧ Logical And
8oó Literal string `8oó`
⬤ All characters satisfy
θ Input string
⬤ All characters satisfy
θ Input string
↧ Lowercased
⌕ Does not start with
ι Outer character
⁺ Prefixed with
h Literal string `h`
… Extended to
μ Inner index
§ Index into
uo Literal string `uo`
Implicitly print
请注意,TIO 上的 Charcoal 版本错误地将其算作ó
一个字节,但 ATO 上的版本却正确无误,或者您可以添加标志-x
,以生成xxd
显示正确字节数的样式转储。
\endgroup
|
,24
„ouIl'hæ„óoâJ8ªÅ?àI11Q~è
或。
解释:
„ou # Push "ou"
I # Push the input-string
l # Lowercase it
'h '# Push "h"
æ # Pop and push its powerset: ["","h"]
„óo # Push "óo"
â # Cartesian product to create all possible pairs:
# [["","ó"],["","o"],["h","ó"],["h","o"]]
J # Join each together: ["ó","o","hó","ho"]
8ª # Append 8: ["ó","o","hó","ho","8"]
Å? # Check for each whether the lowercased input starts with it
à # Check if any is truthy (by leaving the maximum)
I # Push the input-string again
11Q # Check whether it equals 11
~ # Check if either of the two is truthy
è # Use that 0 or 1 to (0-based) index into the "ou"
# (after which the result is output implicitly)
\endgroup
|
Java,44 字节
s->s.matches("(?i)11|(8|h?[oó]).*")?'u':'o'
解释:
s-> // Method with String parameter and character return-type
s.matches("(?i)11|(8|h?[oó]).*")?
// If the String matches the full regex explained below:
'u' // Return 'u'
: // Else:
'o' // Return 'o' instead
正则表达式解释:
该方法隐式匹配整个字符串,并添加前导^
和尾随$
。
(?i)^11|(8|h?[oó]).*$
(?i) # Enable case-insensitive matching
^ $ # Match the entire string
11 # It's "11"
| # OR:
8 # It starts with an "8"
( | ) # or
h? # An optional "h"
[oó] # Followed by either "o" or "ó"
.* # Followed by 0 or more additional characters
\endgroup
|
,64字节
lambda s:re.match("(?i)^h?[oó]|^11$|^8",s)and"u"or"o"
import re
的端口。
\endgroup
|
,字节
- -8 字节,感谢
->s{s=~/^h?[oó]|^11$|^8/i??u:?o}
由于语法几乎相同,因此正则表达式是从中复制粘贴的:D
(以下注释指的是之前的41字节版本)
我喜欢这里的是三个问号如何一起出现(唉,空格不能删除),每个问号都有不同的作用:第一个是布尔表达式的一部分,用于检查值是否为nil
,第二个属于三元运算符,最后一个是的快捷方式'o'
。
\endgroup
2
-
1\begingroup
如果交换?o
,?u
那么您可以省去.nil?
和括号,从而节省 7 个字节。
\endgroup
– -
\begingroup
@Dingus …而且空间也不再需要了。谢谢!
\endgroup
–
|
,49字节
grep -qiE '^h?[oó]|^11$|^8'<<<$1&&echo u||echo o
用作 bash 函数或 bash 脚本的主体,将输入作为第一个参数并输出到 stdout。
解释:
grep -qiE <<<$1 #match on the first argument, don't output matches, case-insensitive, extended expressions
'^h?[oó]|^11$|^8' #the expression we know and love at this point
&&echo u||echo o #if match, output u, o otherwise.
\endgroup
|
,60字节
r:
{{{h,H}? {o,ó,O,Ó}},\8} []*=>u/$ _
\11=>u/$ _ $
[]+=>o
解释
r:
{{{h,H}? {o,ó,O,Ó}},\8} []*=>u/$ _ # match /[hH]?[oóOÓ]|8/ at the start of the word, and replace it all with u
\11=>u/$ _ $ # special case for 11
[]+=>o # everything else is o
\endgroup
|
,110字节
import."regexp"
func f(s string)string{o:="o"
if b,_:=MatchString(`(?i)^h?[oó]|^11$|^8`,s);b{o="u"}
return o}
使用其他人都在使用的不区分大小写的正则表达式。
\endgroup
|
您的意思是否定“该字符串是一个数字,并且它以 8 开头或正好是 11”吗?
\endgroup
–
@Aaron 我否定了,谢谢你纠正我。
\endgroup
–
@LuisMendo 1) 是的,我习惯说“panqueques” 😀 2) 我添加了该语法规则的解释,谢谢。 3) 那是我的错误,我添加了重音并添加了以“o”开头的测试用例。抱歉。
\endgroup
–
我可以将这个问题简化为吗?
\endgroup
–
“u” 用于以“Ho”开头的单词之后— — 你的意思是之前吗?
\endgroup
–
|