Language: C++

#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
int suma(int d);
int a;
char s[100000];
int t(int d){
  int ans=1;
  cin>>s;
  a--;
  while(a>=0){
    if(strlen(s)<d)
      break;
    if(s[d-1]=='*')
      ans*=t(d+1);
    else if(s[d-1]=='+')
      ans*=suma(d+1);
    else{
      ans*=s[d-1]-'0';
      if(a==0)
        break;
      cin>>s;
      a--;
    }
  }
  return ans;
}

int suma(int d){
  int ans=0;
  a--;
  cin>>s;
  while(a>=0){
    if(strlen(s)<d)
      break;
    if(s[d-1]=='*')
      ans+=t(d+1);
    else if(s[d-1]=='+')
      ans+=suma(d+1);
    else{
      if(strlen(s)!=d)
        break;
      ans+=s[d-1]-'0';
      if(a==0)
        break;
      cin>>s;
      a--;
    }
  }
  return ans;
}

int main(){
  int n;
  while(1){
    cin>>s;
    if(strlen(s)==1&&s[0]=='0')
      break;
    n=strlen(s);
    a=0;
    for(int i=0;i<n;i++){
      a*=10;
      a+=s[i]-'0';
    }
    a--;
    cin>>s;
    if(s[0]=='+')
      cout<<suma(2)<<endl;
    else if(s[0]=='*')
      cout<<t(2)<<endl;
    else
      cout<<s<<endl;
  }
}


Compiler output:
a.cc: In function 'int t(int)':
a.cc:10:3: error: 'cin' was not declared in this scope
   10 |   cin>>s;
      |   ^~~
a.cc:4:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    3 | #include<stdio.h>
  +++ |+#include <iostream>
    4 | using namespace std;
a.cc: In function 'int suma(int)':
a.cc:33:3: error: 'cin' was not declared in this scope
   33 |   cin>>s;
      |   ^~~
a.cc:33:3: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc: In function 'int main()':
a.cc:57:5: error: 'cin' was not declared in this scope
   57 |     cin>>s;
      |     ^~~
a.cc:57:5: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:69:7: error: 'cout' was not declared in this scope
   69 |       cout<<suma(2)<<endl;
      |       ^~~~
a.cc:69:7: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:69:22: error: 'endl' was not declared in this scope
   69 |       cout<<suma(2)<<endl;
      |                      ^~~~
a.cc:4:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    3 | #include<stdio.h>
  +++ |+#include <ostream>
    4 | using namespace std;
a.cc:71:7: error: 'cout' was not declared in this scope
   71 |       cout<<t(2)<<endl;
      |       ^~~~
a.cc:71:7: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:71:19: error: 'endl' was not declared in this scope
   71 |       cout<<t(2)<<endl;
      |                   ^~~~
a.cc:71:19: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:73:7: error: 'cout' was not declared in this scope
   73 |       cout<<s<<endl;
      |       ^~~~
a.cc:73:7: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:73:16: error: 'endl' was not declared in this scope
   73 |       cout<<s<<endl;
      |                ^~~~
a.cc:73:16: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'