在这个代码高尔夫挑战,您将验证哈希标签!
输入是一个字符串。如果它是一个有效的哈希标签,则输出一个真实值,否则输出一个假值。
我们将字符串定义为有效的哈希标签,如果..。
#)开头。#2016USElection不是一个有效的hashtag)。_)或数字的任何字符)。您可以假设输入只包含ASCII字符。(如果我们也使用Unicode,那将是不公平的。)
适用基本的密码-高尔夫规则。
特鲁西:
#
#e
#_ABC
#thisisanunexpectedlylongstringxoxoxoxo
#USElection2016法尔西:
Hello, World!
#12thBday
#not-valid
#alsoNotValid!
#!not_a_hash发布于 2016-07-18 12:24:36
函数f()将字符串作为参数,并将int *b修改为1或0,以表示真实/错误。
f(char*p,int*b){for(*b=(*p==35)&&!isdigit(p[1]);*p;++p)*b&=isalnum(*p)||*p==95;}如果字符串始终至少有一个字符(即从不为空字符串),则可以将一个字节削掉79个字节:
f(char*p,int*b){for(*b=(*p==35)&&!isdigit(p[1]);*++p;)*b&=isalnum(*p)||*p==95;}发布于 2016-07-19 10:30:04
import re
re.compile('#(?!\d)\w*).match发布于 2016-07-18 11:49:20
"#"|h"#",?b@lL'(eE,@A:"1234567890":"_"c'eE),@A:"_"ce~hL这不需要正则表达式。
Main predicate, Input (?) is a string
"#" ? = "#"
| Or
h"#", First character of ? is "#"
?b@lL L is the rest of the chars of ? lowercased
'( It is not possible for any char of L that...
eE, Call this char E
@A:"1234567890":"_"c Concatenate the lowercase alphabet with the digits and "_"
'eE E is not a member of that concatenated string
),
@A:"_"c Concatenate the lowercase alphabet with "_"
e~hL One char of that concatenated string is the first char of Lhttps://codegolf.stackexchange.com/questions/85619
复制相似问题