题解 | #Mileage Bank#

Mileage Bank

https://www.nowcoder.com/practice/8ec03ec1fa7544cf84244a441ff9405c

#include <cmath>
#include <iostream>
#include<cstring>
using namespace std;
#define MAX 1000
struct licheng{
    int len;
    char ch;
};
void acmpark(struct licheng li[], int n){
    double temp;
    for (int i = 0; i < n; i++){
        switch(li[i].ch){
            case 'F': li[i].len *= 2;break;
            case 'B': {
                temp = (double)li[i].len * 0.5;
                li[i].len += round(temp);	//用round函数 四舍五入
                break;
            } 
            case 'Y':{
                if (li[i].len <= 500) li[i].len = 500;
                break;
            } 
            default: break;
        }
    }
}
int main() {
    struct licheng li[MAX];
    string begin, end;
    int i = 0;
    while (cin >> begin >> end >> li[i].len >> li[i].ch && begin != "0")
        i++; 
        
        acmpark(li,i);
       
        int sum = 0;
        for (int j = 0; j < i; j++){
            sum += li[j].len;
        }
        cout << sum << endl;
    }

// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务