0
已解决
飞速小程序开发商
初级守护
初级守护
来来来!飞速计算器1.36出来了!!!
#include<iostream>
#include<cstring>
#define clean (system("cls"))
#include<windows.h>
using namespace std;
string a,b;
double c[1005];
bool check(){
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(){
for(int i=0;i<b.size();i++){
if(b[i]=='^'){
return i;
}
}
return -1;
}
int find_(){
for(int i=0;i<b.size();i++){
if(b[i]=='+'||b[i]=='-'){
return i;
}
}
return 0;
}
int findx(){
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]=='^')){
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_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(3000);
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(2000);
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<<"Only four operations and powers can be entered,no 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);
}
int main(){
SetConsoleTitle("飞速计算器 1.36");
goin();
rule();
while(1){
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;
}
b="";
int go=-1;
int 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]=='^'){
j--;
break;
}
}
if(j==a.size())j--;
//cout<<i<<" "<<j<<"\n";
go=j;
string t=a.substr(i,j-i+1);
c[l]=change(t);
b=b+change2(l);
}
}
else if(a[i]!='.'){
b=b+a[i];
}
}
//cout<<b<<"\n";
bool con=0;
while(check()){
int u;
u=findc();
if(u==-1)u=findx();
if(u==-1)u=find_();
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);
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));
//cout<<b<<"\n";
}
if(con){
wrong();
continue;
}
cout<<"="<<c[int(change(b))]<<"\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;
}
有建议就在下方提出吧!