HDU 2700 Parity
奇偶校验
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #define READ() freopen("in.txt", "r", stdin); 5 using namespace std; 6 7 int main() 8 { 9 //READ() 10 char str[256]; 11 while (gets(str)) 12 { 13 if (str[0] == '#') break; 14 int len = strlen(str); 15 int one = 0, zero = 0; 16 for (int i = 0; i < len; i++) 17 { 18 if (str[i] == '0') zero++; 19 else if (str[i] == '1') one++; 20 else break; 21 putchar(str[i]); 22 } 23 if (str[len-1] == 'e') 24 { 25 if (one % 2 == 0) puts("0"); 26 else puts("1"); 27 } 28 else 29 { 30 if (one % 2 == 0) puts("1"); 31 else puts("0"); 32 } 33 } 34 return 0; 35 }