Language: C

typedef string::const_iterator State;

const string C[5] = {"((a x b) x c) x d",
		     "(a x (b x c)) x d",
		     "a x ((b x c) x d)",
		     "a x (b x (c x d))",
		     "(a x b) x (c x d)"};

const char P[3] = {'+','-','*'};

int term(State &now);
int expression(State &now);
int fact(State &now);
int number(State &now);

string solve(int a,int b,int c,int d){
  for(int i = 0; i < 5; i++){
    string s = C[i];
    s[s.find("a")] = '0' + a;
    s[s.find("b")] = '0' + b;
    s[s.find("c")] = '0' + c;
    s[s.find("d")] = '0' + d;
    for(int p1 = 0; p1 < 3; p1++){
      for(int p2 = 0; p2 < 3; p2++){
	for(int p3 = 0; p3 < 3; p3++){
	  string s2 = s;
	  s2[s2.find("x")] = P[p1];
	  s2[s2.find("x")] = P[p2];
	  s2[s2.find("x")] = P[p3];
	  string s3 = s2;
	  s3.erase(remove(all(s3),' '),s3.end());
	  State now = s3.begin();
	  int ans = expression(now);
	  if(ans == 10) return s2;
	}
      }
    }
  }
  return "";
}

int main(){
  int a = 0,b = 0,c = 0,d = 0;
  while(scanf("%d %d %d %d",&a,&b,&c,&d),a|b|c|d){
    int st[4] = {a,b,c,d};
    sort(st,st + 4);
    bool exist = false;
    string res;
    do{
      res = solve(st[0],st[1],st[2],st[3]);
      if(res != ""){
	exist = true;
	break;
      }
    }while(next_permutation(st,st + 4));
    if(exist){
      string r = "(" + res + ")";
      cout<<r<<endl;
    }
    else puts("0");
  }
}

int term(State &now){
  int ret = fact(now);
  while(true){
    if(*now == '*'){
      now++;
      ret *= fact(now);
    }else break;
  }
  return ret;
}

int expression(State &now){
  int ret = term(now);
  while(true){
    if(*now == '+'){
      now++;
      ret += term(now);
    }else if(*now == '-'){
      now++;
      ret -= term(now);
    }else break;
  }
  return ret;
}

int fact(State &now){
  if(*now == '('){
    now++;
    int ret = expression(now);
    now++;
    return ret;
  }else{
    return number(now);
  }
}

int number(State &now){
  int ret = 0;
  while('0' <= (*now) && (*now) <= '9'){
    ret *= 10;
    ret += *now - '0';
    now++;
  }
  return ret;
}

Compiler output:
main.c:1:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '::' token
    1 | typedef string::const_iterator State;
      |               ^~
main.c:3:7: error: unknown type name 'string'
    3 | const string C[5] = {"((a x b) x c) x d",
      |       ^~~~~~
main.c:4:22: error: excess elements in 'const int[5]' initializer
    4 |                      "(a x (b x c)) x d",
      |                      ^~~~~~~~~~~~~~~~~~~
main.c:4:22: note: (near initialization for 'C')
main.c:5:22: error: excess elements in 'const int[5]' initializer
    5 |                      "a x ((b x c) x d)",
      |                      ^~~~~~~~~~~~~~~~~~~
main.c:5:22: note: (near initialization for 'C')
main.c:6:22: error: excess elements in 'const int[5]' initializer
    6 |                      "a x (b x (c x d))",
      |                      ^~~~~~~~~~~~~~~~~~~
main.c:6:22: note: (near initialization for 'C')
main.c:7:22: error: excess elements in 'const int[5]' initializer
    7 |                      "(a x b) x (c x d)"};
      |                      ^~~~~~~~~~~~~~~~~~~
main.c:7:22: note: (near initialization for 'C')
main.c:3:21: error: cannot initialize array of 'int' from a string literal with type array of 'char'
    3 | const string C[5] = {"((a x b) x c) x d",
      |                     ^
main.c:11:15: error: expected ')' before '&' token
   11 | int term(State &now);
      |               ^~
      |               )
main.c:12:21: error: expected ')' before '&' token
   12 | int expression(State &now);
      |                     ^~
      |                     )
main.c:13:15: error: expected ')' before '&' token
   13 | int fact(State &now);
      |               ^~
      |               )
main.c:14:17: error: expected ')' before '&' token
   14 | int number(State &now);
      |                 ^~
      |                 )
main.c:16:1: error: unknown type name 'string'
   16 | string solve(int a,int b,int c,int d){
      | ^~~~~~
main.c: In function 'solve':
main.c:18:5: error: unknown type name 'string'
   18 |     string s = C[i];
      |     ^~~~~~
main.c:19:8: error: request for member 'find' in something not a structure or union
   19 |     s[s.find("a")] = '0' + a;
      |        ^
main.c:20:8: error: request for member 'find' in something not a structure or union
   20 |     s[s.find("b")] = '0' + b;
      |        ^
main.c:21:8: error: request for member 'find' in something not a structure or union
   21 |     s[s.find("c")] = '0' + c;
      |        ^
main.c:22:8: error: request for member 'find' in something not a structure or union
   22 |     s[s.find("d")] = '0' + d;
      |        ^
main.c:26:11: error: unknown type name 'string'
   26 |           string s2 = s;
      |           ^~~~~~
main.c:27:16: error: request for member 'find' in something not a structure or union
   27 |           s2[s2.find("x")] = P[p1];
      |                ^
main.c:28:16: error: request for member 'find' in something not a structure or union
   28 |           s2[s2.find("x")] = P[p2];
      |                ^
main.c:29:16: error: request for member 'find' in something not a structure or union
   29 |           s2[s2.find("x")] = P[p3];
      |                ^
main.c:30:11: error: unknown type name 'string'
   30 |           string s3 = s2;
      |           ^~~~~~
main.c:31:13: error: request for member 'erase' in something not a structure or union
   31 |           s3.erase(remove(all(s3),' '),s3.end());
      |             ^
main.c:31:20: error: implicit declaration of function 'remove' [-Wimplicit-function-declaration]
   31 |           s3.erase(remove(all(s3),' '),s3.end());
      |                    ^~~~~~
main.c:31:27: error: implicit declaration of function 'all' [-Wimplicit-function-declaration]
   31 |           s3.erase(remove(all(s3),' '),s3.end());
      |                           ^~~
main.c:31:42: error: request for member 'end' in something not a structure or union
   31 |           s3.erase(remove(all(s3),' '),s3.end());
      |                                          ^
main.c:32:11: error: unknown type name 'State'
   32 |           State now = s3.begin();
      |           ^~~~~
main.c:32:25: error: request for member 'begin' in something not a structure or union
   32 |           State now = s3.begin();
      |                         ^
main.c:33:21: error: implicit declaration of function 'expression' [-Wimplicit-function-declaration]
   33 |           int ans = expression(now);
      |                     ^~~~~~~~~~
main.c:39:10: error: returning 'char *' from a function with return type 'int' makes integer from pointer without a cast [-Wint-conversion]
   39 |   return "";
      |          ^~
main.c: In function 'main':
main.c:44:9: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   44 |   while(scanf("%d %d %d %d",&a,&b,&c,&d),a|b|c|d){
      |         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | typedef string::const_iterator State;
main.c:44:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   44 |   while(scanf("%d %d %d %d",&a,&b,&c,&d),a|b|c|d){
      |         ^~~~~
main.c:44:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:46:5: error: implicit declaration of function 'sort' [-Wimplicit-function-declaration]
   46 |     sort(st,st + 4);
      |     ^~~~
main.c:47:5: error: unknown type name 'bool'
   47 |     bool exist = false;
      |     ^~~~
main.c:1:1: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
  +++ |+#include <stdbool.h>
    1 | typedef string::const_iterator State;
main.c:47:18: error: 'false' undeclared (first use in this function)
   47 |     bool exist = false;
      |                  ^~~~~
main.c:47:18: note: 'false' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:47:18: note: each undeclared identifier is reported only once for each function it appears in
main.c:48:5: error: unknown type name 'string'
   48 |     string res;
      |     ^~~~~~
main.c:51:14: warning: comparison between pointer and integer
   51 |       if(res != ""){
      |              ^~
main.c:52:17: error: 'true' undeclared (first use in this function)
   52 |         exist = true;
      |                 ^~~~
main.c:52:17: note: 'true' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:55:12: error: implicit declaration of function 'next_permutation' [-Wimplicit-function-declaration]
   55 |     }while(next_permutation(st,st + 4));
      |            ^~~~~~~~~~~~~~~~
main.c:57:7: error: unknown type name 'string'
   57 |       string r = "(" + res + ")";
      |       ^~~~~~
main.c:57:28: error: invalid operands to binary + (have 'char *' and 'char *')
   57 |       string r = "(" + res + ")";
      |                  ~~~~~~~~~ ^
      |                      |     |
      |                      |     char *
      |                      char *
main.c:58:7: error: 'cout' undeclared (first use in this function)
   58 |       cout<<r<<endl;
      |       ^~~~
main.c:58:16: error: 'endl' undeclared (first use in this function)
   58 |       cout<<r<<endl;
      |                ^~~~
main.c:60:10: error: implicit declaration of function 'puts' [-Wimplicit-function-declaration]
   60 |     else puts("0");
      |          ^~~~
main.c:60:10: note: include '<stdio.h>' or provide a declaration of 'puts'
main.c: At top level:
main.c:64:15: error: expected ')' before '&' token
   64 | int term(State &now){
      |               ^~
      |               )
main.c:75:21: error: expected ')' before '&' token
   75 | int expression(State &now){
      |                     ^~
      |                     )
main.c:89:15: error: expected ')' before '&' token
   89 | int fact(State &now){
      |               ^~
      |               )
main.c:100:17: error: expected ')' before '&' token
  100 | int number(State &now){
      |                 ^~
      |                 )