Monday, September 10, 2007

Operator Parsing: Nice Hack

#include 
#include
int main(int argc, char *argv[]){
int i;

printf("((((");
for(i=1;i!=argc;i++){
if( strcmp(argv[i], "^")==0) printf(")^(");
else if(strcmp(argv[i], "*")==0) printf("))*((");
else if(strcmp(argv[i], "/")==0) printf("))/((");
else if(strcmp(argv[i], "+")==0) printf(")))+(((");
else if(strcmp(argv[i], "-")==0) printf(")))-(((");
else printf("%s", argv[i]);
}
printf("))))\n");
return 0;
}

No comments: