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:
a.cc:1:9: error: 'string' does not name a type
    1 | typedef string::const_iterator State;
      |         ^~~~~~
a.cc:3:7: error: 'string' does not name a type
    3 | const string C[5] = {"((a x b) x c) x d",
      |       ^~~~~~
a.cc:11:10: error: 'State' was not declared in this scope
   11 | int term(State &now);
      |          ^~~~~
a.cc:11:17: error: 'now' was not declared in this scope
   11 | int term(State &now);
      |                 ^~~
a.cc:12:16: error: 'State' was not declared in this scope
   12 | int expression(State &now);
      |                ^~~~~
a.cc:12:23: error: 'now' was not declared in this scope
   12 | int expression(State &now);
      |                       ^~~
a.cc:13:10: error: 'State' was not declared in this scope
   13 | int fact(State &now);
      |          ^~~~~
a.cc:13:17: error: 'now' was not declared in this scope
   13 | int fact(State &now);
      |                 ^~~
a.cc:14:12: error: 'State' was not declared in this scope
   14 | int number(State &now);
      |            ^~~~~
a.cc:14:19: error: 'now' was not declared in this scope
   14 | int number(State &now);
      |                   ^~~
a.cc:16:1: error: 'string' does not name a type
   16 | string solve(int a,int b,int c,int d){
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:44:9: error: 'scanf' was not declared in this scope
   44 |   while(scanf("%d %d %d %d",&a,&b,&c,&d),a|b|c|d){
      |         ^~~~~
a.cc:46:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   46 |     sort(st,st + 4);
      |     ^~~~
      |     short
a.cc:48:5: error: 'string' was not declared in this scope
   48 |     string res;
      |     ^~~~~~
a.cc:50:7: error: 'res' was not declared in this scope
   50 |       res = solve(st[0],st[1],st[2],st[3]);
      |       ^~~
a.cc:50:13: error: 'solve' was not declared in this scope
   50 |       res = solve(st[0],st[1],st[2],st[3]);
      |             ^~~~~
a.cc:55:12: error: 'next_permutation' was not declared in this scope
   55 |     }while(next_permutation(st,st + 4));
      |            ^~~~~~~~~~~~~~~~
a.cc:57:13: error: expected ';' before 'r'
   57 |       string r = "(" + res + ")";
      |             ^~
      |             ;
a.cc:58:7: error: 'cout' was not declared in this scope
   58 |       cout<<r<<endl;
      |       ^~~~
a.cc:58:13: error: 'r' was not declared in this scope
   58 |       cout<<r<<endl;
      |             ^
a.cc:58:16: error: 'endl' was not declared in this scope
   58 |       cout<<r<<endl;
      |                ^~~~
a.cc:60:10: error: 'puts' was not declared in this scope
   60 |     else puts("0");
      |          ^~~~
a.cc: At global scope:
a.cc:64:5: error: redefinition of 'int term'
   64 | int term(State &now){
      |     ^~~~
a.cc:11:5: note: 'int term' previously defined here
   11 | int term(State &now);
      |     ^~~~
a.cc:64:10: error: 'State' was not declared in this scope
   64 | int term(State &now){
      |          ^~~~~
a.cc:64:17: error: 'now' was not declared in this scope
   64 | int term(State &now){
      |                 ^~~
a.cc:75:5: error: redefinition of 'int expression'
   75 | int expression(State &now){
      |     ^~~~~~~~~~
a.cc:12:5: note: 'int expression' previously defined here
   12 | int expression(State &now);
      |     ^~~~~~~~~~
a.cc:75:16: error: 'State' was not declared in this scope
   75 | int expression(State &now){
      |                ^~~~~
a.cc:75:23: error: 'now' was not declared in this scope
   75 | int expression(State &now){
      |                       ^~~
a.cc:89:5: error: redefinition of 'int fact'
   89 | int fact(State &now){
      |     ^~~~
a.cc:13:5: note: 'int fact' previously defined here
   13 | int fact(State &now);
      |     ^~~~
a.cc:89:10: error: 'State' was not declared in this scope
   89 | int fact(State &now){
      |          ^~~~~
a.cc:89:17: error: 'now' was not declared in this scope
   89 | int fact(State &now){
      |                 ^~~
a.cc:100:5: error: redefinition of 'int number'
  100 | int number(State &now){
      |     ^~~~~~
a.cc:14:5: note: 'int number' previously defined here
   14 | int number(State &now);
      |     ^~~~~~
a.cc:100:12: error: 'State' was not declared in this scope
  100 | int number(State &now){
      |            ^~~~~
a.cc:100:19: error: 'now' was not declared in this scope
  100 | int number(State &now){
      |                   ^~~