凑个热闹
算法一

程序代码:
#include<stdio.h>
int cal(int b, int * x)
{
const int t[2][8] = {{1, 2, 3, 0, 5, 6, 7, 4}, {6, 7, 4, 5, 0, 1, 2, 3}};
const int r[2][8] = {{0, 1, 1, 1, 0, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 1, 1}};
return r[b][*x = t[b][*x]];
}
int main()
{
int b, r, x;
for(x = 0; (b = getchar()) == '0' || b == '1'; r = cal(b - '0', &x));
puts(r ? "获取一个奖品" : "很遗憾下次努力");
return 0;
}
算法二

程序代码:
#include<stdio.h>
int main()
{
int b[2] = {0}, t, x1, x2, x3;
for(; (t = getchar()) == '0' || t == '1'; b[t -= '0']++);
b[t]--;
x1 = b[0] & 1;
x2 = (b[0] / 2 + (b[1] + 1) / 2) & 1;
x3 = b[1] & 1;
t = t ? !(x2 || x3) : !(x1 && x2);
puts(t ? "获取一个奖品" : "很遗憾下次努力");
return 0;
}
[
本帖最后由 beyondyf 于 2014-1-23 00:50 编辑 ]