问题标题: 飞速计算器 正确代码是最后的 编程平台上点个赞

0
0
已解决
包涵宇
包涵宇
中级天翼
中级天翼

飞速2.08其实已经出来很久了,有些细心地同学已经在编程平台看到了

介绍:

可以输入大{}中[]小()括号,四则运算和次方

优先级提示(从先到后):

1.()

2.[]

3.{}

4.^

5.*/

6.+-

 

这是编程平台的

https://kuding1024.com/#/share?uuid=9a71576bf0684dfe97bddf115fa3c1b4

c++代码

#include<iostream>
#include<cstring>
#define clean (system("cls"))
#include<windows.h>
using namespace std; 
string a,tb;
double c[1005];
int l;
bool wron;
bool check(string b){
	for(int i=0;i<b.size();i++){
		if(b[i]=='+'||b[i]=='-'||b[i]=='*'||b[i]=='/'||b[i]=='^'){
			return 1;
		}
	}
	return 0;
}
int findc(string b){
	for(int i=0;i<b.size();i++){
		if(b[i]=='^'){
			return i;
		}
    }
    return -1;
}
int find_(string b){
	for(int i=0;i<b.size();i++){
		if(b[i]=='+'||b[i]=='-'){
			return i;
		}
    }
    return 0;
}
int findx(string b){
	for(int i=0;i<b.size();i++){
		if(b[i]=='*'||b[i]=='/'){
			return i;
		}
	}
	return -1;
}
double change(string s){
	int l=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='.'){
			l=s.size()-1-i;
		}
	}
	int f=1,idx=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]!='.'){
			idx+=(s[i]-'0')*f;
			f*=10;
		}
	}
	if(l==0)return idx;
	int t=10;
	for(int i=1;i<l;i++)t*=10;
	return idx*1.0/t;
} 
string change2(int tx){
	int b[105],l=0,x=tx;
	while(x!=0){
		l++;
		b[l]=x%10;
		x/=10;
	}
	string out="";
	for(int i=l;i>=1;i--)out=out+char(b[i]+'0');
	return out;
}
bool check2(string t){
	for(int i=0;i<t.size();i++){
		if(!((t[i]>='0'&&t[i]<='9')||t[i]=='+'||t[i]=='-'||t[i]=='*'||t[i]=='/'||t[i]=='.'||t[i]=='^'||t[i]=='('||t[i]==')'||t[i]=='['||t[i]==']'||t[i]=='{'||t[i]=='}')){
			return 1;
		}
	}
	return 0;
}
void wrong(){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红色
    cout<<"Input error\n输入错误";
    Sleep(1500);
}
void goin(){          
	cout<<"                                     |---|\n";
	cout<<"                                     |   |\n";
	cout<<"                                     |---|\n";
	cout<<"                                       |\n";
	cout<<"                                       |  |\n";
	cout<<"                                     --|--|\n";
	cout<<"                                    /  |\n";
	cout<<"                                       /----\n";
	cout<<"                                      /    |\n";
	cout<<"                                     /   -------\n"; 
	cout<<"                                    /    |     |\n"; 
	cout<<"                              ---------------------\n"; 
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);//绿色 
	cout<<"                                飞速小程序开发商\n"; 
	Sleep(1500000);
	clean;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
	cout<<"\n\n\n\n\n\n                                   鑫汇工作室" ;
	Sleep(1500);
	clean;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
    cout<<"A person is a team, this program is written by only one person!\n";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"一个人就是一个团队,此程序仅由一人编写!";
    Sleep(2000);
    clean;
	for(int i=1;i<=3;i++){ 
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);//蓝色 
		cout<<"                                    QUICK Contribution List飞速贡献榜\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色 
		cout<<"                                    Bao Hanyu包涵宇  Wang Ziyao王子耀\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);//白色 
		cout<<"                                             loading.";
		Sleep(500);
		clean;
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);//蓝色 
		cout<<"                                    QUICK Contribution List飞速贡献榜\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
		cout<<"                                    Bao Hanyu包涵宇  Wang Ziyao王子耀\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);//白色 
		cout<<"                                             loading..";
		Sleep(500);
		clean;
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);//蓝色 
		cout<<"                                    QUICK Contribution List飞速贡献榜\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
		cout<<"                                    Bao Hanyu包涵宇  Wang Ziyao王子耀\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);//白色 
		cout<<"                                             loading...";
		Sleep(500);
		clean;
	} 
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
    cout<<"Welcome to the quick calculator!\n";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"欢迎使用飞速计算器!";
    Sleep(1500);
    clean;
} 
void rule(){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"!";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红色
    cout<<"You can only enter four operations, powers and parentheses";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"!\n!";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红色
    cout<<"只能输入四则运算,次方和括号";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"!\n";
    Sleep(3000);
}
double goo(string b){
	bool con=0;
	while(check(b)){
		int u;
		u=findc(b);
		if(u==-1)u=findx(b);
		if(u==-1)u=find_(b);
		int j1,j2;
		for(j1=u-1;j1>=0;j1--){
			if(b[j1]=='+'||b[j1]=='-'||b[j1]=='*'||b[j1]=='/'||b[j1]=='^'){
				j1++;
				break;
			}
		}
		if(j1==-1)j1=0;
		for(j2=u+1;j2<b.size();j2++){
			if(b[j2]=='+'||b[j2]=='-'||b[j2]=='*'||b[j2]=='/'||b[j2]=='^'){
				j2--;
				break;
			}
		}
		if(j2==b.size())j2--;
		string ta=b.substr(j1,u-j1),tb=b.substr(u+1,j2-u);
		if(ta==""||tb==""){
			wron=1;
			return 0x3f3f3f3f;
		}
		double t;
		double t1=c[int(change(ta))],t2=c[int(change(tb))];
		if(b[u]=='^'){
			double tmp=t1;
			int cs=t2;
			if(cs!=t2){
				con=1;
				break;
			}
			for(int i=1;i<cs;i++){
				tmp*=t1;
			}
			t=tmp;
		}
		if(b[u]=='+')t=t1+t2;
		if(b[u]=='-')t=t1-t2;
		if(b[u]=='*')t=t1*t2;
		if(b[u]=='/')t=t1/t2;
		b.erase(j1,j2-j1+1);
		l++;
		c[l]=t;
		b.insert(j1,change2(l));
	}
	if(con){
		wron=1;
		return 0x3f3f3f3f;
	}
	return c[int(change(b))];
}
void HideCursor(){
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO CursorInfo;
	GetConsoleCursorInfo(handle, &CursorInfo);
	CursorInfo.bVisible = false;
	SetConsoleCursorInfo(handle, &CursorInfo);
}
int main(){
	HideCursor(); 
	SetConsoleTitle("飞速计算器 2.08"); 
	system("mode con cols=110 lines=20");  
	goin();
	rule();
    while(1){
    	wron=0;
        clean;
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
    	cout<<"Please enter\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    	cout<<"请输入\n";
    	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);//白色 
    	cin>>a;
    	if(check2(a)){
    		wrong();
    		continue;
		}
    	tb="";
    	int go=-1;
    	l=0;
    	for(int i=0;i<a.size();i++){
    		if(a[i]>='0'&&a[i]<='9'){
    			if(i>go){
    				l++;
    				int j;
    				for(j=i+1;j<a.size();j++){
    					if(a[j]=='+'||a[j]=='-'||a[j]=='*'||a[j]=='/'||a[j]=='^'||a[j]==')'||a[j]==']'||a[j]=='}'){
    						j--;
    						break;
						}
					}
					if(j==a.size())j--;
					go=j;
					string t=a.substr(i,j-i+1);
					c[l]=change(t);
					tb=tb+change2(l);
				}
			}
			else if(a[i]!='.'){
				tb=tb+a[i];
			}
		}
		//*************do parentheses*************
		string tc="";
		for(int i=0;i<tb.size();i++){
			if(wron)break; 
			if(tb[i]=='('){
				int j;
				for(j=i+1;j<=tb.size();j++){
					if(tb[j]=='('||tb[j]==']'||tb[j]=='['||tb[j]=='{'||tb[j]=='}'){
						wron=1;
						break;
					}
					if(tb[j]==')'){
						j--;
						break;
					}
				}
				if(wron)break;
				if(j>=tb.size()){
					wron=1;
					break;
				}
				string t=tb.substr(i+1,j-(i+1)+1);
				l++;
				c[l]=goo(t);
				tc=tc+change2(l);
				i=j+1;
				if(wron){
					break;
				}
			}
			else if(tb[i]!=')'){
				tc=tc+tb[i];
			}
		}
		if(wron){
			wrong();
			continue;
		}
		tb="";
		for(int i=0;i<tc.size();i++){
			if(wron)break; 
			if(tc[i]=='['){
				int j;
				for(j=i+1;j<=tc.size();j++){
					if(tc[j]=='['||tc[j]=='{'||tc[j]=='}'){
						wron=1;
						break;
					}
					if(tc[j]==']'){
						j--;
						break;
					}
				}
				if(wron)break;
				if(j>=tc.size()){
					wron=1;
					break;
				}
				string t=tc.substr(i+1,j-(i+1)+1);
				l++;
				c[l]=goo(t);
				tb=tb+change2(l);
				i=j+1;
				if(wron){
					break;
				}
			}
			else if(tc[i]!=']'){
				tb=tb+tc[i];
			}
		}
		if(wron){
			wrong();
			continue;
		}
		tc="";
		for(int i=0;i<tb.size();i++){
			if(wron)break; 
			if(tb[i]=='{'){
				int j;
				for(j=i+1;j<=tb.size();j++){
					if(tb[j]=='{'){
						wron=1;
						break;
					}
					if(tb[j]=='}'){
						j--;
						break;
					}
				}
				if(wron)break;
				if(j>=tb.size()){
					wron=1;
					break;
				}
				string t=tb.substr(i+1,j-(i+1)+1);
				l++;
				c[l]=goo(t);
				tc=tc+change2(l);
				i=j+1;
				if(wron){
					break;
				}
			}
			else if(tb[i]!='}'){
				tc=tc+tb[i];
			}
		}
		if(wron){
			wrong();
			continue;
		}
		double ans=goo(tc);
		if(wron){
			wrong();
			continue;
		}
		else cout<<"="<<ans<<"\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
    	cout<<"Press Enter to retype\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    	cout<<"按回车键重新录入\n";
        getchar();
        getchar();
    }
    return 0;
}

 

 

——————————————————————————————

下面是投票

1.是否输出计算过程

2.是否选择中英文(工程量较大,编程平台无法实现)

3.是否增加“跳过开头”

(大家都可以投票)

 

-------------------------------------------------------------------------

(我是分割线)

这个帖子的100个豆,将奖励给率先找到3个BUG的人(c++和编程平台都行)

 

 

最后,我在附上飞速的官方链接

GO

包涵宇在2021-07-28 20:31:48追加了内容

额。。。上面的代码有点问题,我更正一下:

#include<iostream>
#include<cstring>
#define clean (system("cls"))
#include<windows.h>
using namespace std; 
string a,tb;
double c[1005];
int l;
bool wron;
bool check(string b){
	for(int i=0;i<b.size();i++){
		if(b[i]=='+'||b[i]=='-'||b[i]=='*'||b[i]=='/'||b[i]=='^'){
			return 1;
		}
	}
	return 0;
}
int findc(string b){
	for(int i=0;i<b.size();i++){
		if(b[i]=='^'){
			return i;
		}
    }
    return -1;
}
int find_(string b){
	for(int i=0;i<b.size();i++){
		if(b[i]=='+'||b[i]=='-'){
			return i;
		}
    }
    return 0;
}
int findx(string b){
	for(int i=0;i<b.size();i++){
		if(b[i]=='*'||b[i]=='/'){
			return i;
		}
	}
	return -1;
}
double change(string s){
	int l=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='.'){
			l=s.size()-1-i;
		}
	}
	int f=1,idx=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]!='.'){
			idx+=(s[i]-'0')*f;
			f*=10;
		}
	}
	if(l==0)return idx;
	int t=10;
	for(int i=1;i<l;i++)t*=10;
	return idx*1.0/t;
} 
string change2(int tx){
	int b[105],l=0,x=tx;
	while(x!=0){
		l++;
		b[l]=x%10;
		x/=10;
	}
	string out="";
	for(int i=l;i>=1;i--)out=out+char(b[i]+'0');
	return out;
}
bool check2(string t){
	for(int i=0;i<t.size();i++){
		if(!((t[i]>='0'&&t[i]<='9')||t[i]=='+'||t[i]=='-'||t[i]=='*'||t[i]=='/'||t[i]=='.'||t[i]=='^'||t[i]=='('||t[i]==')'||t[i]=='['||t[i]==']'||t[i]=='{'||t[i]=='}')){
			return 1;
		}
	}
	return 0;
}
void wrong(){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红色
    cout<<"Input error\n输入错误";
    Sleep(1500);
}
void goin(){          
	cout<<"                                     |---|\n";
	cout<<"                                     |   |\n";
	cout<<"                                     |---|\n";
	cout<<"                                       |\n";
	cout<<"                                       |  |\n";
	cout<<"                                     --|--|\n";
	cout<<"                                    /  |\n";
	cout<<"                                       /----\n";
	cout<<"                                      /    |\n";
	cout<<"                                     /   -------\n"; 
	cout<<"                                    /    |     |\n"; 
	cout<<"                              ---------------------\n"; 
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);//绿色 
	cout<<"                                飞速小程序开发商\n"; 
	Sleep(1500);
	clean;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
	cout<<"\n\n\n\n\n\n                                   鑫汇工作室" ;
	Sleep(1500);
	clean;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
    cout<<"A person is a team, this program is written by only one person!\n";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"一个人就是一个团队,此程序仅由一人编写!";
    Sleep(2000);
    clean;
	for(int i=1;i<=3;i++){ 
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);//蓝色 
		cout<<"                                    QUICK Contribution List飞速贡献榜\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色 
		cout<<"                                    Bao Hanyu包涵宇  Wang Ziyao王子耀\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);//白色 
		cout<<"                                             loading.";
		Sleep(500);
		clean;
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);//蓝色 
		cout<<"                                    QUICK Contribution List飞速贡献榜\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
		cout<<"                                    Bao Hanyu包涵宇  Wang Ziyao王子耀\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);//白色 
		cout<<"                                             loading..";
		Sleep(500);
		clean;
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);//蓝色 
		cout<<"                                    QUICK Contribution List飞速贡献榜\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
		cout<<"                                    Bao Hanyu包涵宇  Wang Ziyao王子耀\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);//白色 
		cout<<"                                             loading...";
		Sleep(500);
		clean;
	} 
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
    cout<<"Welcome to the quick calculator!\n";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"欢迎使用飞速计算器!";
    Sleep(1500);
    clean;
} 
void rule(){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"!";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红色
    cout<<"You can only enter four operations, powers and parentheses";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"!\n!";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红色
    cout<<"只能输入四则运算,次方和括号";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    cout<<"!\n";
    Sleep(3000);
}
double goo(string b){
	bool con=0;
	while(check(b)){
		int u;
		u=findc(b);
		if(u==-1)u=findx(b);
		if(u==-1)u=find_(b);
		int j1,j2;
		for(j1=u-1;j1>=0;j1--){
			if(b[j1]=='+'||b[j1]=='-'||b[j1]=='*'||b[j1]=='/'||b[j1]=='^'){
				j1++;
				break;
			}
		}
		if(j1==-1)j1=0;
		for(j2=u+1;j2<b.size();j2++){
			if(b[j2]=='+'||b[j2]=='-'||b[j2]=='*'||b[j2]=='/'||b[j2]=='^'){
				j2--;
				break;
			}
		}
		if(j2==b.size())j2--;
		string ta=b.substr(j1,u-j1),tb=b.substr(u+1,j2-u);
		if(ta==""||tb==""){
			wron=1;
			return 0x3f3f3f3f;
		}
		double t;
		double t1=c[int(change(ta))],t2=c[int(change(tb))];
		if(b[u]=='^'){
			double tmp=t1;
			int cs=t2;
			if(cs!=t2){
				con=1;
				break;
			}
			for(int i=1;i<cs;i++){
				tmp*=t1;
			}
			t=tmp;
		}
		if(b[u]=='+')t=t1+t2;
		if(b[u]=='-')t=t1-t2;
		if(b[u]=='*')t=t1*t2;
		if(b[u]=='/')t=t1/t2;
		b.erase(j1,j2-j1+1);
		l++;
		c[l]=t;
		b.insert(j1,change2(l));
	}
	if(con){
		wron=1;
		return 0x3f3f3f3f;
	}
	return c[int(change(b))];
}
void HideCursor(){
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO CursorInfo;
	GetConsoleCursorInfo(handle, &CursorInfo);
	CursorInfo.bVisible = false;
	SetConsoleCursorInfo(handle, &CursorInfo);
}
int main(){
	HideCursor(); 
	SetConsoleTitle("飞速计算器 2.08"); 
	system("mode con cols=110 lines=20");  
	goin();
	rule();
    while(1){
    	wron=0;
        clean;
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
    	cout<<"Please enter\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    	cout<<"请输入\n";
    	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);//白色 
    	cin>>a;
    	if(check2(a)){
    		wrong();
    		continue;
		}
    	tb="";
    	int go=-1;
    	l=0;
    	for(int i=0;i<a.size();i++){
    		if(a[i]>='0'&&a[i]<='9'){
    			if(i>go){
    				l++;
    				int j;
    				for(j=i+1;j<a.size();j++){
    					if(a[j]=='+'||a[j]=='-'||a[j]=='*'||a[j]=='/'||a[j]=='^'||a[j]==')'||a[j]==']'||a[j]=='}'){
    						j--;
    						break;
						}
					}
					if(j==a.size())j--;
					go=j;
					string t=a.substr(i,j-i+1);
					c[l]=change(t);
					tb=tb+change2(l);
				}
			}
			else if(a[i]!='.'){
				tb=tb+a[i];
			}
		}
		//*************do parentheses*************
		string tc="";
		for(int i=0;i<tb.size();i++){
			if(wron)break; 
			if(tb[i]=='('){
				int j;
				for(j=i+1;j<=tb.size();j++){
					if(tb[j]=='('||tb[j]==']'||tb[j]=='['||tb[j]=='{'||tb[j]=='}'){
						wron=1;
						break;
					}
					if(tb[j]==')'){
						j--;
						break;
					}
				}
				if(wron)break;
				if(j>=tb.size()){
					wron=1;
					break;
				}
				string t=tb.substr(i+1,j-(i+1)+1);
				l++;
				c[l]=goo(t);
				tc=tc+change2(l);
				i=j+1;
				if(wron){
					break;
				}
			}
			else if(tb[i]!=')'){
				tc=tc+tb[i];
			}
		}
		if(wron){
			wrong();
			continue;
		}
		tb="";
		for(int i=0;i<tc.size();i++){
			if(wron)break; 
			if(tc[i]=='['){
				int j;
				for(j=i+1;j<=tc.size();j++){
					if(tc[j]=='['||tc[j]=='{'||tc[j]=='}'){
						wron=1;
						break;
					}
					if(tc[j]==']'){
						j--;
						break;
					}
				}
				if(wron)break;
				if(j>=tc.size()){
					wron=1;
					break;
				}
				string t=tc.substr(i+1,j-(i+1)+1);
				l++;
				c[l]=goo(t);
				tb=tb+change2(l);
				i=j+1;
				if(wron){
					break;
				}
			}
			else if(tc[i]!=']'){
				tb=tb+tc[i];
			}
		}
		if(wron){
			wrong();
			continue;
		}
		tc="";
		for(int i=0;i<tb.size();i++){
			if(wron)break; 
			if(tb[i]=='{'){
				int j;
				for(j=i+1;j<=tb.size();j++){
					if(tb[j]=='{'){
						wron=1;
						break;
					}
					if(tb[j]=='}'){
						j--;
						break;
					}
				}
				if(wron)break;
				if(j>=tb.size()){
					wron=1;
					break;
				}
				string t=tb.substr(i+1,j-(i+1)+1);
				l++;
				c[l]=goo(t);
				tc=tc+change2(l);
				i=j+1;
				if(wron){
					break;
				}
			}
			else if(tb[i]!='}'){
				tc=tc+tb[i];
			}
		}
		if(wron){
			wrong();
			continue;
		}
		double ans=goo(tc);
		if(wron){
			wrong();
			continue;
		}
		else cout<<"="<<ans<<"\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);//青色
    	cout<<"Press Enter to retype\n";
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);//黄色 
    	cout<<"按回车键重新录入\n";
        getchar();
        getchar();
    }
    return 0;
}

对大家造成的不便,请大家谅解

包涵宇在2021-07-28 20:33:09追加了内容

换个标题

包涵宇在2021-07-29 14:59:42追加了内容

点个赞啊~

编程平台上

包涵宇在2021-07-30 19:20:33追加了内容

ding


0
已采纳
王泽轩
王泽轩
资深天翼
资深天翼

加入高精度就更好了

0
0
汪艾辰
汪艾辰
高级光能
高级光能

树太大,他就计算不了,会一直卡在那儿。

0
0
王文博
王文博
缔造者之神
缔造者之神

鑫汇工作室的“鑫”无法正常显示,这虽然是编程平台的问题,但是我们也要尽快解决。

我想到了一个办法:

    金

  金  金

这样输出可以吗?

0
0
王文博
王文博
缔造者之神
缔造者之神

1.最好输出

2.不需要

3.要增加

0
王文博
王文博
缔造者之神
缔造者之神

没反应???

王文博在2021-07-28 18:53:30追加了内容

更离谱了!

0
0
我要回答