五、Balloon Comes!

    xiaoxiao2021-04-17  47

    Problem Description The contest starts now! How excited it is to see balloons floating around. You, one of the best programmers in HDU, can get a very beautiful balloon if only you have solved the very very very… easy problem. Give you an operator (+,-,*, / –denoting addition, subtraction, multiplication, division respectively) and two positive integers, your task is to output the result. Is it very easy? Come on, guy! PLMM will send you a beautiful Balloon right now! Good Luck!

    Input Input contains multiple test cases. The first line of the input is a single integer T (0

    #include<iostream> #include<iomanip> using namespace std; int main() { int n, b,a; char s; cin>>n; while(n--) { cin>>s>>a>>b; if(s=='+') { cout<<a+b<<endl; } if(s=='-') { cout<<a-b<<endl; } if(s=='*') { cout<<a*b<<endl; } if(s=='/') { if(a%b==0) cout<<a/b<<endl; else cout<<setprecision(2)<<fixed<< (float)a/b<<endl; // cout<<setprecision(2)<<fixed<< (float)a/(float)b<<endl; //printf("%.2f\n",(float)a/b); } } return 0; }

    这里有个小问题

    当我使用代码 选择G++ 是报错误结果的

    cout<<setprecision(2)<<fixed<< (float)a/b<<endl;

    但是选C++ 就是正确的 若使用

    printf("%.2f\n",(float)a/b);

    是G++ C++ 没有问题的;

    转载请注明原文地址: https://ju.6miu.com/read-674390.html

    最新回复(0)