pat 甲级 1011 World Cup Betting

简单题目,一次通过了
嘻嘻嘻
odd 几率

注意保留取整问题

猪:
printf(“%.2lf”);可能会出现5舍6入的情况。关于测试数据37.98,可能由于编译器版本不同,在我编译器上也出现了37.975保留两位小数变成37.97的情况,5舍6入,此时最好的处理办法就是在结果上加上0.001.

#include<iostream>  
#include<cmath>  
using namespace std;  
int main()  
{  
    double a=2.5;  
    cout<<ceil(a)<<endl;   //向上取整  
    cout<<floor(a)<<endl;   //向下取整  
    cout<<round(a)<<endl;   //四舍五入  
    //不使用函数实现  
    //向下取整  
    cout<<(int)a<<endl;  
    //向上取整  
    cout<<(a>(int)a?(int)a+1:(int)a)<<endl;  
    //四舍五入  
    cout<<(int)(a+0.5)<<endl;  
    return 0;  
}  
#include <cstdio>
#include <iostream>

using namespace std;

double sum;

int main(){

    sum = 1;
    for(int i=0; i<3; i++){

        double a, b, c, max;
        cin >> a >> b >> c;
        if(a>b) {
            if(a>c) {
                max = a;
                cout << 'W' << " ";     
            }
        }
        else {
            if(b>c) {
                max = b;
                cout << 'T' << " ";
            }
            else {
                max = c;
                cout << 'L' << " ";
            }
        }
        sum *= max;
    }

    sum = (sum*0.65-1)*2 + 0.001;
    printf("%.2f",sum);

    return 0;
}

猜你喜欢

转载自blog.csdn.net/mdzz_z/article/details/81268822
今日推荐