把字符串转成数字,然后计算
#include
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
#include "mcstring.h"
using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::set;
using std::vector;
unsigned ctu(const string&r){
static string num[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
for(unsigned i=0;i<10;i++){
if(r==num[i]){
return i;
}
}
return 0x10;
}
int _tmain()
{
cout<<"输入:"<
vector
while(!str.empty()){
do{
cin>>str;
}while(str.empty());
value.push_back(str);
if(str[0]=='=')break;
}
vector
unsigned long a=0,b=0;
bool flag=false;
for(size_t i=0;i
case '+': if(flag){flag=false;temp.push_back(a);a=0;temp.push_back(0x10000000);}break;
case '-': if(flag){flag=false;temp.push_back(a);a=0;temp.push_back(0x20000000);}break;
case '*': if(flag){flag=false;temp.push_back(a);a=0;temp.push_back(0x30000000);}break;
case '/': if(flag){flag=false;temp.push_back(a);a=0;temp.push_back(0x40000000);}break;
case '&': if(flag){flag=false;temp.push_back(a);a=0;temp.push_back(0x50000000);}break;
case '|': if(flag){flag=false;temp.push_back(a);a=0;temp.push_back(0x60000000);}break;
case '=': if(flag){flag=false;temp.push_back(a);a=0;temp.push_back(0x70000000);}break;
default:
flag=true;
b=ctu(value[i]);
if(b&0x10){
cout<<"检测出一处错误:“"<
}
a=10*a+b;
}
}
for(size_t i=0;i
temp[i+1]=temp[i+1]*temp[i-1];
temp[i-1]=0x80000000;
i++;
}else if(temp[i]==0x40000000){
if(temp[i+1]==0){
cout<<"检测一处错误:除数为0,默认一处理"<
}
temp[i+1]=temp[i-1]/temp[i+1];
temp[i-1]=0x80000000;
i++;
}
}
for(size_t i=0;i
int j=1;
while(temp[i+j]&0xf0000000&&!(temp[i+j]&0xf000000))j++;
temp[i+j]=temp[i+j]+temp[i-1];
temp[i-1]=0x80000000;
i=i+j;
}else if(temp[i]==0x20000000){
int j=1;
while(temp[i+j]&0xf0000000&&!(temp[i+j]&0xf000000))j++;
temp[i+j]=temp[i-1]-temp[i+j];
temp[i-1]=0x80000000;
i=i+j;
}
}
for(size_t i=0;i
int j=1;
while(temp[i+j]&0xf0000000&&!(temp[i+j]&0xf000000))j++;
temp[i+j]=temp[i+j]&temp[i-1];
temp[i-1]=0x80000000;
}else if(temp[i]==0x60000000){
int j=1;
while(temp[i+j]&0xf0000000&&!(temp[i+j]&0xf000000))j++;
temp[i+j]=temp[i+j]|temp[i-1];
temp[i-1]=0x80000000;
}
}
vector
for(size_t i=0;i
if(temp[i]&0xf000000)tmp.push_back(temp[i]);
}
if(temp[i]==0x70000000){
tmp.push_back(temp[i]);
}
}
for(size_t i=0;i
else cout<
cout<
return 0;
}
//参考下,搞了差不多两个小时,不想改了