#15338: c answer


blackconqueror (boweichen)

學校 : 國立臺南第一高級中學
編號 : 58182
來源 : [220.132.250.41]
最後登入時間 :
2020-06-01 10:17:42
d681. BinaryCount -- 葆葆 | From: [140.114.197.199] | 發表日期 : 2018-09-29 10:43

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//void checkbool(char *,int *,int oper);
int main(int argc, char *argv[]) {
char a[500];
int i,u=1;
while(gets(a)!=0){
for(i=0;a[i]!='\0';i+=u){//format
u=1;
if(a[i]==' '){
if(a[i+1]!='\0'){
if(a[i+1]=='a'){
printf("&&");
u=5;
}else if(a[i+1]=='o'){
printf("||");
u=4;
}
}else{
printf(" = ");
}
}else{
printf("%c",a[i]);
}
}
//result
//puts(a);
int temp[5];
for(i=0;i<5;i++){
temp[i]=a[i]-'0';
//printf("%d\n",temp[i]);
}
int count=0,oper=0;//oper 0 and 1 or
for(i=5;a[i]!='\0';i++){
if(a[i]!='0'&&a[i]!='1'){
if(a[i]=='a') oper=0;//and
if(a[i]=='o') oper=1;//or
count=0;
//printf("now at first if: i=%d count=%d oper=%d a[i]=%c\n",i,count,oper,a[i]);
}else{
//checkbool(&(a[i]),&(temp[count]),oper);
if(!oper){//and
if(temp[count]==1&&(a[i]-'0')==1)
temp[count]=1;
else
temp[count]=0;
}else{//or
if(temp[count]==0&&(a[i]-'0')==0)
temp[count]=0;
else
temp[count]=1;
}
count++;
//printf("now at second if: i=%d count=%d oper=%d a[i]=%c\n",i,count,oper,a[i]);
//printf("now the temp[i] is : %d\n",temp[i]);
}
}
for(i=0;i<5;i++) printf("%d",temp[i]);
printf("\n");
}


return 0;
}
/*void checkbool(char *a,int *temp,int oper){
if(!oper){//and
if(*temp==1&&(*a-'0')==1)
*temp=1;
else
*temp=0;
}else{//or
if(*temp==0&&(*a-'0')==0)
*temp=0;
else
*temp=1;
}
}*/

 
ZeroJudge Forum