Unlike most languages, Python evaluates a
as it would be done in mathematics, actually comparing the three
numbers, as opposed to comparing the boolean a to
c
. The correct way to write this in C (and many
others) would be a.
この課題では、Python
/直感的な表現から任意の長さの比較チェーンを展開し、他言語での記述方法まで拡張することが課題です。
仕様
Your program will have to handle the operators:
==, !=, <, >, <=, >=
.- The input will have comparison chains using only
integers. - Don’t worry about the trueness of any of the
comparisons along the way, this is purely a parsing/syntactical
challenge. - The input won’t have any whitespace to prevent answers
that trivialize parsing by splitting on spaces. - However, your output may have a single space
surrounding either just the&&
‘s, or both the
comparison operators and the&&
‘s, or neither, but
be consistent.
テストケース
Input Output
---------------------------------------------------------------
3<4<5 3<4 && 4<5
3<4<5<6<7<8<9 3<4 && 4<5 && 5<6 && 6<7 && 7<8 && 8<9
3<5==6<19 3<5 && 5==6 && 6<19
10>=5<7!=20 10>=5 && 5<7 && 7!=20
15==15==15==15==15 15==15 && 15==15 && 15==15 && 15==15
This is code-golf, so shortest code in bytes
wins!
ベストアンサー