fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.  
  6. string str,newstr="\0";
  7. getline(cin,newstr,'\0');
  8. int sum=0,sub=0,prod=1,div=0;
  9. int num=0;
  10. string::size_type pos=newstr.find("sum");
  11. string::size_type pos1=newstr.find("prod");
  12. if(pos != std::string::npos)
  13. {
  14. if(newstr[pos]=='s'&&newstr[pos+1]=='u'&&newstr[pos+2]=='m')
  15. {
  16. for(int i=pos+3; newstr[i]; i++)
  17. {
  18. num=0;
  19. while(isdigit(newstr[i]))
  20. {
  21. num=(num*10)+int(newstr[i]-'0');
  22. i++;
  23. }
  24. sum+=num;
  25. }
  26. }
  27. }
  28. if(pos1 != std::string::npos)
  29. {
  30. if(newstr[pos1]=='p'&&newstr[pos1+1]=='r'&& newstr[pos1+2]=='o' && newstr[pos1+3]=='d')
  31. {
  32. for(int i=pos1+4; newstr[i]; i++)
  33. {
  34. num=0;
  35. while(isdigit(newstr[i]))
  36. {
  37. num=(num*10)+int(newstr[i]-'0');
  38. i++;
  39. }
  40. prod*=num;
  41. cout<<prod;
  42.  
  43. }
  44.  
  45.  
  46. }
  47. }
  48. cout<<sum<<endl;
  49.  
  50.  
  51. }
  52.  
  53.  
Success #stdin #stdout 0s 3476KB
stdin
{
"expr": {
"prod": {
"elem": [
"4",
"6",
"3",
"7"
]
}
}
}
stdout
00000000000000000000000000000000000000