挑战编程 程序设计竞赛训练手册-1.6.3 旅行(The Trip)
来源:互联网 发布:淘宝二手官方下载 编辑:程序博客网 时间:2024/05/22 13:50
挑战编程 程序设计竞赛训练手册-1.6.3 旅行(The Trip)
import java.text.DecimalFormat;public class problem_The_Trip {/** * @param args */public static void main(String[] args) {double[] fee = {15.00,15.01,3.00,3.01};//double[] fee = {10.00,20.00,30.00};String result = String.valueOf(caculate(fee,Double.parseDouble(avg(fee))));//先得到平均值avg,再计算平摊费用result = result.substring(0,result.indexOf(".")+3);//截取运算结果 小数点后两位System.out.print(result);//输出最小总交易金额}private static String avg(double[] fee){//计算平均值double sum = 0;for(int i = 0;i<fee.length;i++){sum = sum + fee[i];}double avg = sum/fee.length;DecimalFormat df = new DecimalFormat("0.000");//指定格式,保留3位小数//System.out.println(df.format(avg));return df.format(avg);//返回带有3位小数的结果}private static double caculate(double[] fee,double avg){//System.out.println(avg);double avgmoney = 0;//最小总交易金额double tempjudge = 0;//判断支出、收入哪个多double in = 0;//记录入款double out = 0;//记录还款for ( int i = 0 ; i<fee.length ; i++){tempjudge = tempjudge+(avg - fee[i]);//收钱多 为负//还钱多 为正if(fee[i]-avg>=0){//多付了in = in + fee[i]-avg;//统计收入的钱} else{//少付了out = out + avg-fee[i];//统计支出的钱}}if(tempjudge>=0){//还钱多avgmoney = in ;//以收入款为最小总交易金额}else{//入款多avgmoney = out;//以支出款为平摊款}//DecimalFormat df = new DecimalFormat("0.00");//System.out.println(avgmoney);//System.out.println(df.format(avgmoney));return avgmoney;//输出结算值为最小总交易金额}}
- 挑战编程 程序设计竞赛训练手册-1.6.3 旅行(The Trip)
- 序-挑战编程 程序设计竞赛训练手册
- 《挑战编程:程序设计竞赛训练手册》
- 挑战编程 程序设计竞赛训练手册-1.6.2 扫雷(Minesweeper)
- 挑战编程 程序设计竞赛训练手册-1.6.7 将军(Check_the_Check)
- 挑战编程 程序设计竞赛训练手册-1.6.1 3n+1问题(3n+1 Problem)
- 挑战编程程序设计竞赛训练手册(Programming Challenges)
- 《挑战编程:程序设计竞赛训练手册》- 题解(全)
- 挑战编程 程序设计竞赛训练手册-1.6.4 液晶显示屏(LC-Display)
- 挑战编程 程序设计竞赛训练手册-1.6.5 图形化编辑器(Graphical Editor)
- 挑战编程 程序设计竞赛训练手册-1.6.6 解释器(Interpreter)
- 挑战编程 程序设计竞赛训练手册-1.6.8 澳大利亚投票(Australian Voting)
- 《挑战编程:程序设计竞赛训练手册》- 题解(第一章 - 第八章)
- 《挑战编程:程序设计竞赛训练手册》- 题解(第一章 - 第八章)
- 《挑战编程:程序设计竞赛训练手册》- 题解(第一章 - 第八章)
- 1.6.3 旅行 The Trip
- 程序设计竞赛训练手册
- (挑战编程_1_3)The Trip
- App_Code 文件夹在vs2010中Web Application找不到
- 爆笑如雷的笑话分享
- my quick sort
- 迷宫
- Bluetooth Core Architecture Blocks (蓝牙核心架构)(一)
- 挑战编程 程序设计竞赛训练手册-1.6.3 旅行(The Trip)
- hbernate学习(三)一对一双向关联
- 敏捷日志2013-1-21
- 嵌入式linux应用开发完全手册学习笔记三(windows、linux下工具使用)
- 硬链接和软链接(hard link&soft link)
- Poj 1042 Gone Fishing
- Toast 和Timer与 Can't create handler inside thread that has not called Looper.prepare()问题
- id software编程规范
- 如何将shp数据导入Oracle Spatial