#include<stdio.h>
void to16bit(int n, char s[])
{
int i = 16;
while (--i >= 0)
{
s[i] = n % 2 + '0';
n /= 2;
}
}
int calc7bit(char s[], int index)
{
int factor = 1, r = 0, i;
for (i = index + 6; i > index; i--)
{
r += (s[i] - '0') * factor;
factor *= 2;
}
return s[index] == '0' ? r : -r;
}
int main()
{
int n;
while (scanf("%d", &n), n != -1)
{
int num, i, j = 0, total = 16 * n, sum = 0;
char s[16], r[total];
while (n--)
{
scanf("%d", &num);
to16bit(num, s);
for (i = 0; i < 16; i++)
r[j++] = s[i];
}
for (i = 0; i < total; i += 7)
sum += calc7bit(r, i);
printf("%d\n", sum);
}
return 0;
}
ZOJ-2729
最新推荐文章于 2018-06-10 23:50:35 发布