3 solutions
-
6
声明:这是老师的代码
不愧是老师的代码
#include <bits/stdc++.h> using namespace std; double nibolan(){ char c[20]; cin >> c; switch (c[0]){ case '+': return nibolan() + nibolan(); case '-': return nibolan() - nibolan(); case '*': return nibolan() * nibolan(); case '/': return nibolan() / nibolan(); default: return atof(c); break; } } int main(int argc, char **argv){ printf("%f",nibolan()); return 0; }
-
1
分享一下写了两小时的⑩
#include<iostream> #include<iomanip> #include<string> #include<stack> #include<cstdio> #include<math.h> using namespace std; string a[114]; stack<double> s; double sum; int len=1; double t3,t4; char t; void prepare(char n,double a,double b,double &sum){ if(n=='+') sum=a+b; else if(n=='-') sum=a-b; else if(n=='*') sum=a*b; else if(n=='/') sum=a/b; } int main() { while(cin>>a[len]) len++; cout<<endl<<endl; for(; len>0; len--) { if(a[len]=="+"||a[len]=="-"||a[len]=="*"||a[len]=="/") { t3=s.top(); s.pop(); t4=s.top(); s.pop(); t=a[len][0]; prepare(t,t3,t4,sum); s.push(sum); } else { sum=atof(a[len].c_str()); s.push(sum); } } printf ("%f",s.top()); return 0; }
是栈我们没救了
-
0
#include <bits/stdc++.h> using namespace std; double fufuhang(){ char c[20]; cin>>c; switch(c[0]){ case '+': return fufuhang() + fufuhang(); case '-': return fufuhang() - fufuhang(); case '*': return fufuhang() * fufuhang(); case '/': return fufuhang() / fufuhang(); default: return atof(c); break; } }//大名为武则天计算器! int main(){ cout<<fufuhang()<<".000000"; return 0; }
- 1
Information
- ID
- 684
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 145
- Accepted
- 52
- Uploaded By