magical tree question in hackerearth

*The little Monk loves to play with strings. One day he was going to a forest. On the way to the forest he saw a Big Tree(The magical tree of the forest). The magic of the tree was that, every leaf of the tree was in the format of string(having some value). Monk wants to have these type of leaves. But he can take only one. Help Monk to choose the most valuable leaf.

Format of the leaf:

a+b+c-d+c+d-x-y+x…, i.e. it contains a string holding a mathematical expression, and the value of that expression will be value of that particular leaf.

e.g. 4+2-5+3+2-4
value: 2
Input:

First line contains L(No of leaves on the Tree).
Each of the next L line contain a string(Expression).

Output:

Print a single line having value of most valuable string.

Constraints:

* The Expression will have only + and - operations
* String will contain only single valued digits.

SAMPLE INPUT
4
8-6+2+4+3-6+1
1+1+1+1
2+3+6+8-9
2+7+1-6
SAMPLE OUTPUT
10

**<>
#include
using namespace std;

int main() {
int n;
cin >>n;

char arr[n];
for(int i=0;i<n;i++)
{
string s;
cin >>s;
s=arr[i];
}
int max=0;
for(int i=0;i<n;i++)
    if(arr[i]>max)
    max=arr[i];
   
cout <<max;
return 0;

}

When did you handled + and - operations ??

you need to compute calculations and then find max…

not directly…

in your example :

#input should be converted to
8-6+2+4+3-6+1 = 5
1+1+1+1 = 4
2+3+6+8-9 = 10
2+7+1-6 =4
#then find
max(5,4,10,4)= 10

this can be done easily using switch case(if else would also work… switch case is only for clarity and it makes code more readable)
#sample code is

  for(i=0;i<n;i++){    
    string s;    
    cin >> s;  

  ans=s[0]-'0';  

  for(i=1;i<s.length();i+=2){  
   temp=s[i+1]-'0';    

   switch(s[i]){  
      case '+' :  
             ans+=temp;
             break;
      case '-' :   
             ans-=temp;
             break;  
   }     
  
  }  
 a[i]=ans;  
 }      

and then find max from a[i]…