Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

string gettopnum(string str){
	string rst = "";
	REP(i,str.size()){
		if(str[i]=='*'||str[i]=='+') break;
		else rst += str[i];
	}
	return rst;
}

string strerase(string instr,int num){
	string rst = "";
	for(int i=num;i<instr.size();i++){
		rst += instr[i];
	}
	return rst;
}
ll int calc1(string str){//multiplication-first
	stack<ll int> st;
	string rststr = gettopnum(str);
	if(rststr!="") st.push((ll int)stoi(rststr));
	if(rststr!="") strerase(str,log10((double)stoi(rststr))+1);
	while(str.size()!=0){
		//cout << str << endl;
		if(str[0]=='*'){
			strerase(str,1);
			ll int tmp = stoi(gettopnum(str));
			str.erase(str,(int)log10((double)tmp)+1);
			ll int tmp2 = st.top();
			st.pop();
			st.push(tmp*tmp2);
		}else if(str[0]=='+'){
			str.rase(str,1);
			ll int tmp = stoi(gettopnum(str));
			st.push(tmp);
			str.erase(str,(int)log10((double)tmp)+1);
		}
	}
	ll int rst = 0;
	while(!st.empty()){
		rst += st.top();
		st.pop();
	}
	return rst;
}

ll int calc2(string str){////multiplication-first2
	//cout << str << endl;
	string rststr = gettopnum(str);
	ll int rst;
	if(rststr!="") rst = stoi(rststr);
	if(rststr!="") strerase(str,(int)log10((double)rst)+1);
	if(str.size()==0) return rst;
	else if(str[0]=='*') {
		strerase(str,1);
		return rst*calc2(str);
	}else if(str[0]=='+'){
		strerase(str,1);
		return rst+calc2(str);
	}
	//dummy
	return -1;
}

ll int calc3(string str){//leftto-right
	string rststr = gettopnum(str);
	if(rststr!="") strerase(str,(int)log10((double)stoi(rststr))+1);
	ll int rst = stoi(rststr);
	while(str.size()!=0){
		//cout << str << endl;
		if(str[0]=='*'){
			strerase(str,1);
			ll int tmp = stoi(gettopnum(str));
			rst *= tmp;
			strerase(str,(int)log10((double)tmp)+1);
		}else if(str[0]=='+'){
			strerase(str,1);
			ll int tmp = stoi(gettopnum(str));
			rst += tmp;
			strerase(str,(int)log10((double)tmp)+1);
		}
	}
	return rst;
}

int main(){
	string str;
	cin >> str;
	ll int ans;
	cin >> ans;
	ll int rst1 = calc1(str);
	ll int rst2 = calc3(str);
	cout << rst1 << " " << rst2 << endl;
	if(rst1==ans){
		if(rst2==ans) cout << 'U' << endl;
		else cout << 'M' << endl;
	}else{
		if(rst2==ans) cout << 'L' << endl;
		else cout << 'I' << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'long long int calc1(std::string)':
a.cc:49:34: error: no matching function for call to 'std::__cxx11::basic_string<char>::erase(std::string&, int)'
   49 |                         str.erase(str,(int)log10((double)tmp)+1);
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:2114:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(size_type, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
 2114 |       erase(size_type __pos = 0, size_type __n = npos)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2114:23: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'}
 2114 |       erase(size_type __pos = 0, size_type __n = npos)
      |             ~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:2134:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(__const_iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; iterator = std::__cxx11::basic_string<char>::iterator; __const_iterator = std::__cxx11::basic_string<char>::const_iterator]'
 2134 |       erase(__const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2134:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/basic_string.h:2154:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(__const_iterator, __const_iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; iterator = std::__cxx11::basic_string<char>::iterator; __const_iterator = std::__cxx11::basic_string<char>::const_iterator]'
 2154 |       erase(__const_iterator __first, __const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2154:30: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'std::__cxx11::basic_string<char>::__const_iterator' {aka 'std::__cxx11::basic_string<char>::const_iterator'}
 2154 |       erase(__const_iterator __first, __const_iterator __last)
      |             ~~~~~~~~~~~~~~~~~^~~~~~~
a.cc:54:29: error: 'std::string' {aka 'class std::__cxx11::basic_string<char>'} has no member named 'rase'; did you mean 'erase'?
   54 |                         str.rase(str,1);
      |                             ^~~~
      |                             erase
a.cc:57:34: error: no matching function for call to 'std::__cxx11::basic_string<char>::erase(std::string&, int)'
   57 |                         str.erase(str,(int)log10((double)tmp)+1);
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:2114:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(size_type, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
 2114 |       erase(size_type __pos = 0, size_type __n = npos)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2114:23: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'}
 2114 |       erase(size_type __pos = 0, size_type __n = npos)
      |             ~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:2134:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(__const_iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; iterator = std::__cxx11::basic_string<char>::iterator; __const_iterator = std::__cxx11::basic_string<char>::const_iterator]'
 2134 |       erase(__const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2134:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/basic_string.h:2154:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::iterator std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::erase(__const_iterator, __const_iterator) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; iterator = std::__cxx11::basic_string<char>::iterator; __const_iterator = std::__cxx11::basic_string<char>::const_iterator]'
 2154 |       erase(__const_iterator __first, __const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/basic_string.h:2154:30: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'std::__cxx11::basic_string<char>::__const_iterator' {aka 'std::__cxx11::basic_string<char>::const_iterator'}
 2154 |       erase(__const_iterator __first, __const_iterator __last)
      |             ~~~~~~~~~~~~~~~~~^~~~~~~