杭电1170 Balloon Comes!

版权声明:ACM代码随意转载。算法描述需备注来源。谢谢合作。 https://blog.csdn.net/Sensente/article/details/89810106

杭电1170 http://acm.hdu.edu.cn/showproblem.php?pid=1170

题目大意:

有点像逆波兰表达式。但是要简单的多。

注意:像 / 1 2 这样的输入 应该输出 0.50(保留两位) 而 "/ 2 1" 则是2(无小数保留)。

AC代码:

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <stack>
#include <stdlib.h>
//#define DEBUG
using namespace std;
typedef long long ll;
double m;
int t;
char ch;
double a,b;
int main() {
    while(cin>>t) {
        while(t--) {
            cin>>ch;
            cin>>a>>b;
            if(ch=='+') cout<<a+b<<endl;
            if(ch=='-') cout<<a-b<<endl;
            if(ch=='*') {
                ll sum=a*b;
                cout<<sum<<endl;
            }
            if(ch=='/') {
                    double ans=a/b;
                    if(ans==(int)ans) cout<<ans<<endl;
                    else printf("%.2lf\n",ans);
                }
            }
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Sensente/article/details/89810106