纺丝
物品纺丝是一种搜索引擎优化技术,搜索引擎优化器在文章目录、Web2.0站点或其他反向链接源上发布相关内容的唯一版本。
它偶尔会被网站作者在自己的网站上使用,但通常会避免使用,因为旋转内容的质量会低于手写内容。旋转的工作是重写现有的文章或文章的一部分,用任意数量的备选版本替换特定的单词、短语、句子甚至整个段落,以提供与每个旋转略有不同的变化。
此过程可以完全自动化或手动重写。您今天的工作将是创建一个程序或函数来解释包含自旋税的字符串,该字符串是程序读取可用的不同选项的语法。下面是一个使用SPINTA税的示例字符串:
{Hello|Hi there|Bonjour}, user! {What's up?|How are you?|Feeling alright?|I caught a fish!}正如您所看到的,字符串中要被“旋转”的部分被用大括号括起来,其中各个选项被|字符分割。下面是一些可以产生的例句。
Hi there, user! What's up?
Hello, user! How are you?
Bonjour, user! Feeling alright?
Hello, user! What's up?
Hi there, user! I caught a fish!如果您选择接受,您的任务是创建一个程序或函数,该程序或函数接受可能包含或不包含自旋税的输入字符串,然后打印该字符串的5个版本,随机从每个选项块中选择一个选项。你可以做一些假设:
{This|is {an|one}|example})。|、{和}字符不会发生在其他任何地方,只会出现在自旋赋值块中。1. {A|The|One} {quick|magnificent|charming|lucky|fast|super|cool} {gold|tan|yellow|white|brown|silver} {beaver|packrat|cat|lion|tiger|fox|dog|wolf} {consumed|ate|pilfered} my {pastry|strudel|cake}.
-------------------------------------------
One cool brown wolf consumed my pastry.
...(3 more here)...
The charming yellow beaver ate my cake.
-------------------------------------------
2. This sentence is valid, and happens to have no Spintax!
-------------------------------------------
This sentence is valid, and happens to have no Spintax!
...(3 more here)...
This sentence is valid, and happens to have no Spintax!
-------------------------------------------
3. {beg|get|ton|sun|bun|can|top|big}{2|3|4|5}{A|B|C|D|E|F|G}{2|3|4|5|6|7}{at|as|be|ex|hi|}{!|#|%}
-------------------------------------------
top2F2hi%
...(3 more here)...
big3E4ex#第四个测试可以找到这里。
这是密码-高尔夫,所以赢的字节最少。
发布于 2015-06-19 20:06:47
V5sOMcR\|scR\{cz\}V5sOMcR\|scR\{cz\} : z = input()
V5 : do this 5 times
cz\} : split z on the } character
cR\{ : split each element of the resulting list on {
s : join the list of lists back into a list of strings
cR\| : split these strings on the | character
OM : Choose a random element from each inner list
s : join those choices, and print them发布于 2015-06-19 21:51:50
{`{.*?}`{);(;"|/.,R*F=}X}5*解释:
{...}5* repeat 5 times
`{.*?}` regex to match "spintax" sections
{...}X replace with...
);(; remove first and last characters (the curly brackets)
"|/ split on |
.,R* multiply length of that array by a random number
F= take the floor of that and get the nth element of the array(注意: 0.7.0版本是在发布此问题之后发布的,但答案仍然有效,因为构成该版本的所有提交都是在发布此问题之前进行的。)
发布于 2015-06-19 22:15:24
为输入字符串周围的引号添加了两个字节。如果不需要,请告诉我。
在这里试试
import re,random
s=input()
exec"print''.join(t*(t!=''and(t[0]!='{'))or random.choice(t[1:].split('|'))for t in re.split('({.*?)}',s));"*5https://codegolf.stackexchange.com/questions/51891
复制相似问题