The title is roughly described as follows :

Enter six numbers , On behalf of CNY Yes HKD Exchange rate of ,USD Yes CNY Exchange rate of ,GBP Yes USD exchange rate , Enter the number of currencies , Type of currency to be imported , Types of results (MAX or MIN), as 1 2
3 100 CNY MAX. be careful , Allow multiple lines of input .

Entry requirements : The number cannot be negative , There cannot be a decimal point , The string must be a presence value .... Wait a long time ..

Result requirements :MAX Why? Why ,MIN Why? Why .

Analysis of difficulties : The meaning of the question is not very easy to understand , there MAX, It starts with the largest currency ?MIN Solving from the minimum currency ?!!! There is also a more cumbersome test ...

An example is given as follows :

input

1 2 3  100 CNY MAX

16 GBP 2 USD

output

3 2 2 1200 CNy MAX

ERROR

(⊙o⊙)… I don't remember the description of the title clearly .. Or code it directly
package com.syr.test.t1; import java.util.Scanner; /** * @author sunyiran *
@createTime 2019-11-24 21:10 */ public class Main { /** *
If we design according to the object-oriented idea , Then we should design an object to solve the problem */ public static class SolutionWay { /** * Defining constants
*/ private static final String GBP = "GBP"; private static final String USD =
"USD"; private static final String CNY = "CNY"; private static final String HKD
= "HKD"; private static final String MAX = "MAX"; private static final String
MIN = "MIN"; private static final String ERROR = "ERROR"; /** * with HKD As the benchmark exchange rate */
private static int gbpRate; private static int usdRate; private static int
cnyRate; private static int inputNum; private static String inputType; private
static String resultType; private static void setParam(int a, int b, int c, int
num, String inputT, String resultT) { gbpRate = a * b * c; usdRate = a * b;
cnyRate = a; inputNum = num; inputType = inputT; resultType = resultT; }
private static int getRate(String type) { switch (type) { case GBP: return
gbpRate; case USD: return usdRate; case CNY: return cnyRate; default: return 1;
} } private static boolean checkNum(String num) { char c1 = num.charAt(0); if
(c1 < '1' || c1 > '9') { return false; } for (int i = 1; i < num.length(); i++)
{ char c = num.charAt(i); if (c < '0' || c > '9') { return false; } } return
true; } private static boolean checkType(String type) { return type.equals(HKD)
|| type.equals(CNY) || type.equals(USD) || type.equals(GBP); } private static
boolean checkResultType(String resultType) { return resultType.equals(MAX) ||
resultType.equals(MIN); } /** * Max It's from GBP From the beginning * * @return */ private static
String getMaxResult() { int tempV = getRate(inputType) * inputNum;
StringBuilder result = new StringBuilder(); if (tempV / gbpRate > 0) {
result.append(tempV / gbpRate).append(' ').append("GBP "); tempV = tempV %
getRate(GBP); } if (tempV / usdRate > 0) { result.append(tempV /
usdRate).append(' ').append("USD "); tempV = tempV % getRate(USD); } if (tempV
/ cnyRate > 0) { result.append(tempV / cnyRate).append(' ').append("CNY ");
tempV = tempV % getRate(CNY); } if (tempV > 0) { result.append(tempV).append('
').append("HKD"); } return result.toString(); } /** * min Applied HKD * * @return */
private static String getMinResult() { return inputNum * getRate(inputType) + "
HKD"; } private static String computer(String input) { String[] strArr =
input.split("\\s"); if (strArr.length == 6 && (checkNum(strArr[0]) &&
checkNum(strArr[1]) && checkNum(strArr[2]) && checkNum(strArr[3]) &&
checkType(strArr[4]) && checkResultType(strArr[5]))) {
setParam(Integer.parseInt(strArr[0]), Integer.parseInt(strArr[1]),
Integer.parseInt(strArr[2]), Integer.parseInt(strArr[3]), strArr[4],
strArr[5]); if (resultType.equals(MAX)) { return getMaxResult(); } else {
return getMinResult(); } } else { return ERROR; } } } public static void
main(String[] args) { Scanner in = new Scanner(System.in); StringBuilder result
= new StringBuilder(); while (in.hasNextLine()) {
result.append(SolutionWay.computer(in.nextLine())).append("\n"); }
System.out.println(result); } }
 

 

Technology
©2019-2020 Toolsou All rights reserved,
Error summary -myBatis plus paging use easyPOI Import Excel data In the problem of target detection “ recall Recall”,“ Accuracy Precision”vue use vue-clipboard2 Realize the function of copy link C In language switch sentence Wechat applet (uni-app)url Parameter transfer object hive compress &&hdfs Merge small files hive Summary of processing methods for a large number of small files use spring Of AntPathMatcher matching url route Linux Page replacement algorithm C Language implementation