Parity

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
int main() {
freopen("parity.in", "r", stdin);
freopen("parity.out", "w", stdout);
char ch, str[35];
int one=0, zero=0, fExit=0;
while(1) {
scanf("%s", &str);
for(int i=0; i<35; i++) {
if(str[i]=='o'){
for(int j=0; j<i; j++) {
printf("%c", str[j]);
}
if(one%2==0) printf("1");
else printf("0");
printf("\n");
one=0;
zero=0;
break;
}
if(str[i]=='e') {
for(int j=0; j<i; j++) {
printf("%c", str[j]);
}
if(one%2==0) printf("0");
else printf("1");
printf("\n");
one=0;
zero=0;
break;
}
if(str[i]=='#'){
fExit=1;
break;
}
if(str[i]=='1')one++;
if(str[i]=='0')zero++;
}
if(fExit==1) break;
}
return 0;
}