CiscoOA #4
Binary Linked List to Decimal
估计简单可在线判题
Each node of a linked list stores 0 or 1, and the head node holds the most significant bit. The input is the sequence of values from head to tail, and leading 0s are allowed; output the corresponding exact non-negative decimal integer. You do not need to build actual linked list nodes in your program.
输入格式
The first line contains N, and the second line contains N values of 0/1. Original bound: 1≤N≤64. The maximum answer is 2^64−1=18446744073709551615; it cannot be replaced by a signed 64-bit overflow result, and the most significant bit is not restricted to 0.
输出格式
Output a single integer, the answer.
样例 1
输入:
7
0 0 1 1 0 1 0
输出:
26
样例 2
输入:
3
1 0 0
输出:
4
样例 3
输入:
1
0
输出:
0
样例说明
The outputs of the three public examples are, in order: 26; 4; 0. Verified by independent enumeration or direct simulation.