算法 {计算器(加减乘除指数对数运算)}
定义
POW( a,b): 表示a^b
;
LOG( a, b): 表示log_a{b}
;
支持使用 比如1e6, 1E4
语法
算法
模板
性质
由于加减的优先级低 我们先根据+,-
把他拆分成各个子式 (每个子式 都是乘除的),然后每个子式 再根据*/
划分;
代码
//{ ___Calculator
auto ___Calculator = []( std::string _s){
using Type_ = long double;
for( auto it = _s.find( ' '); it != string::npos; _s.erase( it, 1), it = _s.find( ' ')){}
ASSERT_( _s.size() > 0, _s);
std::function<Type_(std::string)> Addition, Multiplication;
auto Single = [&]( std::string _s)->Type_{
ASSERT_( _s.size() > 0, _s);
Type_ ANS = 0;
if( _s[0]>='0' && _s[0]<='9'){
ANS = std::stod( _s);
}
else if( _s.substr( 0, 3)=="POW"){
_s.erase( 0, 3);
ASSERT_( _s.size()>=2 && _s.front()=='(' && _s.back()==')', _s);
_s.erase( _s.begin()); _s.erase( std::prev(_s.end()));
int N = _s.size();
int Comma =