首页 > 专题系列 > Java解POJ > POJ 1326 Mileage Bank [解题报告] Java
2013
11-09

POJ 1326 Mileage Bank [解题报告] Java

Mileage Bank

问题描述 :

Mileage program of ACM (Airline of Charming Merlion) is really nice for the travelers flying frequently. Once you complete a flight with ACM, you can earn ACMPerk miles in your ACM Mileage Bank depended on mileage you actual fly. In addition, you can use the ACMPerk mileage in your Mileage Bank to exchange free flight ticket of ACM in future.

The following table helps you calculate how many ACMPerk miles you can earn when you fly on ACM.


When you fly ACM Class Code You'll earn

First Class F Actual mileage + 100% mileage Bonus

Business Class B Actual mileage + 50% mileage Bonus

Economy Class Y
1-500 miles 500 miles
500+ miles Actual mileage

It’s shown that your ACMPerk mileage consists of two parts. One is your actual flight mileage (the minimum ACMPerk mileage for Economy Class for one flight is 500 miles), the other is the mileage bonus (its accuracy is up to 1 mile) when you fly in Business Class and First Class. For example, you can earn 1329 ACMPerk miles, 1994 ACMPerk miles and 2658 ACMPerk miles for Y, B or F class respectively for the fly from Beijing to Tokyo (the actual mileage between Beijing and Tokyo is 1329 miles). When you fly from Shanghai to Wuhan, you can earn ACMPerk 500 miles for economy class and ACMPerk 650 miles for business class (the actual mileage between Shanghai and Wuhan is 433 miles).

Your task is to help ACM build a program for automatic calculation of ACMPerk mileage.

输入:

The input file contains several data cases. Each case has many flight records, each per line. The flight record is in the following format:

OriginalCity DistanceCity ActualMiles ClassCode

Each case ends with a line of one zero.

A line of one # presents the end of the input file.

输出:

Output the summary of ACMPerk mileages for each test case, one per line.

样例输入:

Beijing Tokyo 1329 F
Shanghai Wuhan 433 Y
0
#

样例输出:

3158

温馨提示:

When calculate bonus ,be sure you rounded x.5 up to x+1

解题代码:

import java.util.*;   
import java.text.*;   
  
class FRecord   
{   
    String from;   
    String to;   
    int miles;   
    String type;   
       
    public FRecord(String a, String b, int c, String d)   
    {   
        this.from = a;   
        this.to = b;   
        this.miles = c;   
        this.type = d;   
    }   
       
}   
  
public class Main {   
  
    public static void main(String[] args) {   
        Scanner cin = new Scanner(System.in);   
        ArrayList record = new ArrayList();   
           
        while(true)   
        {   
            String tmp = cin.nextLine();   
               
            if(tmp.equals("#"))   
                break;   
            else if(tmp.equals("0"))   
            {   
                int total = getSummary(record);   
                record.clear();   
                System.out.println(total);   
            }   
            else  
            {   
                String[] str = tmp.split(" ");   
                FRecord fr = new FRecord(str[0], str[1],    
                        Integer.valueOf(str[2]).intValue(), str[3]);   
                record.add(fr);   
            }   
        }   
    }   
       
    private static int getSummary(ArrayList record)   
    {   
        int result = 0;   
           
        Iterator iter = record.iterator();   
        while(iter.hasNext())   
        {   
            FRecord fr = (FRecord)iter.next();   
            if(fr.type.equals("F"))   
            {   
                result += fr.miles * 2;   
                DecimalFormat df = new DecimalFormat("#");   
                result = Integer.valueOf(df.format(result)).intValue();   
            }   
            else if(fr.type.equals("B"))   
            {   
                result += fr.miles;   
                result += (fr.miles + 1)/2;   
                DecimalFormat df = new DecimalFormat("#");   
                result = Integer.valueOf(df.format(result)).intValue();   
            }   
                   
            else  
            {   
                if(fr.miles > 500)   
                {   
                    result += fr.miles;   
                    DecimalFormat df = new DecimalFormat("#");   
                    result = Integer.valueOf(df.format(result)).intValue();   
                }   
                       
                else  
                {   
                    result += 500;   
                    DecimalFormat df = new DecimalFormat("#");   
                    result = Integer.valueOf(df.format(result)).intValue();   
                }   
                       
            }   
        }   
           
        return result;   
    }   
  
}

  1. 站长好。我是一个准备创业的互联网小白,我们打算做一个有关国*际*游*学的平台。手上也有了一些境外资源。现阶段的团队现在没有cto.原意出让一些管理股寻找一个靠谱的技术专家做合伙人, 不知道是不是能得到您的帮助。发个帖子或者其他方式。期待您的回应。可以加我微信tianxielemon聊聊。

  2. Often We don’t set up on weblogs, but I would like to condition that this established up really forced me individually to do this! considerably outstanding publish