Odd-even interleaving


Submit solution

Points: 20
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

題目說明

<1123檢定考題>
程式輸入一連串數字,第1個輸入值是n表示陣列長度,第2到n+1個輸入值是陣列內容,輸入值都是大於0且小於1000的整數。n大於等於2。
若陣列內容為奇數偶數交錯,換句話說,陣列中完全沒有相鄰的奇數,也沒有相鄰的偶數,則輸出1,否則輸出0。

輸入

一連串數字,第1個輸入值是n表示陣列長度,第2到n+1個輸入值是陣列內容,輸入值都是大於0且小於1000的整數。n大於等於2。

輸出

若陣列內容為奇數偶數交錯,換句話說,陣列中完全沒有相鄰的奇數,也沒有相鄰的偶數,則輸出1,否則輸出0。

sample input0

4 22 31 40 51

sample output0

1

sample input1

4 31 51 42 63

sample output1

0

sample input2

 2 10 11

sample output2

1

Comments

There are no comments at the moment.