zoj 1622 Switch

来源:互联网 发布:sql存储过程经典实例 编辑:程序博客网 时间:2024/06/11 07:32
#include "stdio.h"#include "memory.h"int light[10010];int main(){int i, evencount1, evencount2, oddcount1, oddcount2, evencount = 0, oddcount = 0, num;while (scanf("%d", &num) != EOF){evencount1 = 0;evencount2 = 0;oddcount1 = 0;oddcount2 = 0;memset(light, 0, sizeof(light));for (i = 0; i < num; i++)scanf("%d", &light[i]);for (i = 0; i < num; i++){if (i % 2 == 0 && light[i] == 0)evencount1++;else if (i % 2 != 0 && light[i] == 1)oddcount1++;else if (i % 2 == 0 && light[i] == 1)evencount2++;else if (i % 2 != 0 && light[i] == 0)oddcount2++;}evencount = evencount1 + oddcount1;oddcount = evencount2 + oddcount2;if (evencount > oddcount)printf("%d\n", oddcount);elseprintf("%d\n", evencount);}}

原创粉丝点击