Challenge programming Programming Competition Training Manual-1.6.3 travel (the trip)

Source: Internet
Author: User

Challenge ProgrammingProgramDesign Competition Training Manual-1.6.3Travel(The trip)

Import Java. text. decimalformat; public class problem_the_trip {/*** @ Param ARGs */public static void main (string [] ARGs) {double [] parts = {15.00, 15.01, 3.00, 3.01}; // double [] rows = {10.00, 20.00, 30.00}; string result = string. valueof (caculate (random, double. parsedouble (AVG (cost); // first obtain the average AVG, and then calculate the amortized cost result = result. substring (0, result. indexof (". ") + 3); // truncates the operation result to two digits after the decimal point. out. print (result); // The minimum total output transaction amount} Private Static string AVG (double [] average) {// calculate the average value of double sum = 0; For (INT I = 0; I <strong. length; I ++) {sum = sum + hour [I];} double AVG = sum/hour. length; decimalformat df = new decimalformat ("0.000"); // specify the format, retain three decimal places // system. out. println (DF. format (avg); Return DF. format (avg); // returns results with three decimal places} Private Static double caculate (double [] Random, double avg) {// system. out. println (avg); double avgmoney = 0; // The minimum total transaction amount; double tempjudge = 0; // determine the amount of expenditure and income, double in = 0; // double out = 0; // record the payment for (INT I = 0; I <strong. length; I ++) {tempjudge = tempjudge + (avg-Token [I]); // The amount of money received is negative. // If (then [I]-AVG> = 0) {// The overpay in = in + then [I]-AVG; // money for statistics} else {// out = out + AVG-income [I]; // money for statistics} If (tempjudge> = 0) {// pay back more avgmoney = In; // The minimum total transaction amount based on the income} else {// Add more avgmoney = out; // pay-as-you-go for expenditure} // decimalformat df = new decimalformat ("0.00"); // system. out. println (avgmoney); // system. out. println (DF. format (avgmoney); Return avgmoney; // The output settlement value is the minimum total transaction amount }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.