所以基本上,这个程序读取5个数字: 十、 是的,从,跳,直到
每个数字之间用空格隔开。举个例子:
3 4 1 1 14
X = 3
Y = 4
1 = startFrom
jump = 1
until = 14
为此,我使用了:
#get X, Y, startFrom, jump, until
parameters = raw_input()
parametersList = parameters.split()
X = int(parametersList[0])
Y = int(parametersList[1])
#start from startFrom
startFrom = int(parametersList[2])
#jumps of <jump>
jump = int(parametersList[3])
#until (and including) <until>
until = int(parametersList[4])
程序输出一个链(或者你想怎么称呼它),我们称之为BOOZ
和BANG
,当BOOZ
是X时,如果数字中存在(即X是2,我们是23,所以它是一个BOOZ)。为了检查(我使用:map(int, str(currentPos))
当我的currentPos
(我们的数字)一开始基本上是startFrom
,并且随着我们的进步(每次添加跳跃),它越来越接近until
),或者如果X除以currentPos(X%num == 0
)。i、 e:X是2,我们是34,它也是一个BOOZ
)。你知道吗
BANG
是相同的,但是有Y。如果currentPos
同时是BOOZ
&;BANG
,则输出是BOOZ-BANG
。你知道吗
startFrom, startFrom+ jump, startFrom+2*jump, startFrom+3*jump, ..., until
我们知道读取的数字是int
类型的,但我们需要确保它们对游戏有效。
X和Y必须介于1和9之间。否则,我们打印(在所有5个数字都被读取之后):X and Y must be between 1 and 9
并退出程序。
此外,跳转不能为0。如果是,我们打印jump can't be 0
并退出程序。否则,如果我们不能使用jump
跳转到达until
(如果startFrom+ n * jump == until
当n
是一个整数),那么我们需要打印can't jump from <startFrom> to <until>
并退出程序。
我的算法在那里太混乱了,有很多ifs之类的,所以我也需要帮助。)
因此,对于我们的第一个示例(3 4 1 1 14
),输出应该是:
1,2,BOOZ,BANG,5,BOOZ,7,BANG,BOOZ,10,11,BOOZ-BANG,BOOZ,BANG
另一个例子:
-4 -3 4 0 19
输出:
X and Y must be between 1 and 9
juump can't be 0
另一个:
5 3 670 7 691
输出:
BOOZ,677,BANG,691
另一个:
0 3 4 -5 24
输出:
X and Y must be between 1 and 9
can't jump from 4 to 24
另一个:
3 4 34 3 64
输出:
BOOZ-BANG,BOOZ,BANG,BOOZ-BANG,BANG,BANG,BANG,55,58,61,BANG
我的程序是太乱了(我做了一个有很多如果循环。。包括ifcurrentPos==until
,因此在该原因中,它不会打印最后一个打印项的逗号(,
)。。但就像我说的,所有的一切都是如此混乱,国际单项体育联合会的条件是如此漫长和混乱,我只是把它全部删除,并决定在这里要求一个更好的解决方案。你知道吗
谢谢你们 我希望这足够清楚
我的版本没有
if
:)获取逗号的最简单方法是将循环移动到生成器中
样本输出
相关问题 更多 >
编程相关推荐