購(gòu)物單
小明剛剛找到工作,老板人很好,只是老板夫人很愛(ài)購(gòu)物。老板忙的時(shí)候經(jīng)常讓小明幫忙到商場(chǎng)代為購(gòu)物。小明很厭煩,但又不好推辭。
這不,XX大促銷又來(lái)了!老板夫人開(kāi)出了長(zhǎng)長(zhǎng)的購(gòu)物單,都是有打折優(yōu)惠的。
小明也有個(gè)怪癖,不到萬(wàn)不得已,從不刷卡,直接現(xiàn)金搞定。
現(xiàn)在小明很心煩,請(qǐng)你幫他計(jì)算一下,需要從取款機(jī)上取多少現(xiàn)金,才能搞定這次購(gòu)物。
取款機(jī)只能提供100元面額的紙幣。小明想盡可能少取些現(xiàn)金,夠用就行了。
你的任務(wù)是計(jì)算出,小明最少需要取多少現(xiàn)金。
以下是讓人頭疼的購(gòu)物單,為了保護(hù)隱私,物品名稱被隱藏了。
**** 180.90 88折
**** 10.25 65折
**** 56.14 9折
**** 104.65 9折
**** 100.30 88折
**** 297.15 半價(jià)
**** 26.75 65折
**** 130.62 半價(jià)
**** 240.28 58折
**** 270.62 8折
**** 115.87 88折
**** 247.34 95折
**** 73.21 9折
**** 101.00 半價(jià)
**** 79.54 半價(jià)
**** 278.44 7折
**** 199.26 半價(jià)
**** 12.97 9折
**** 166.30 78折
**** 125.50 58折
**** 84.98 9折
**** 113.35 68折
**** 166.57 半價(jià)
**** 42.56 9折
**** 81.90 95折
**** 131.78 8折
**** 255.89 78折
**** 109.17 9折
**** 146.69 68折
**** 139.33 65折
**** 141.16 78折
**** 154.74 8折
**** 59.42 8折
**** 85.44 68折
**** 293.70 88折
**** 261.79 65折
**** 11.30 88折
**** 268.27 58折
**** 128.29 88折
**** 251.03 8折
**** 208.39 75折
**** 128.88 75折
**** 62.06 9折
**** 225.87 75折
**** 12.89 75折
**** 34.28 75折
**** 62.16 58折
**** 129.12 半價(jià)
**** 218.37 半價(jià)
**** 289.69 8折
需要說(shuō)明的是,88折指的是按標(biāo)價(jià)的88%計(jì)算,而8折是按80%計(jì)算,余者類推。
特別地,半價(jià)是按50%計(jì)算。
請(qǐng)?zhí)峤恍∶饕獜娜】顧C(jī)上提取的金額,單位是元。
答案是一個(gè)整數(shù),類似4300的樣子,結(jié)尾必然是00,不要填寫(xiě)任何多余的內(nèi)容。
特別提醒:不許攜帶計(jì)算器入場(chǎng),也不能打開(kāi)手機(jī)。
程序如下
public class Java17_1 {
public static double CouDis(double dis) {
if(dis>9) return dis/100;
return dis/10;
}
public static void main(String[] args) {
String str =
"**** 180.90 88Z" +
"**** 10.25 65Z" +
"**** 56.14 9Z" +
"**** 104.65 9Z" +
"**** 100.30 88Z" +
"**** 297.15 5Z" +
"**** 26.75 65Z" +
"**** 130.62 5Z" +
"**** 240.28 58Z" +
"**** 270.62 8Z" +
"**** 115.87 88Z" +
"**** 247.34 95Z" +
"**** 73.21 9Z" +
"**** 101.00 5Z" +
"**** 79.54 5Z" +
"**** 278.44 7Z" +
"**** 199.26 5Z" +
"**** 12.97 9Z" +
"**** 166.30 78Z" +
"**** 125.50 58Z" +
"**** 84.98 9Z" +
"**** 113.35 68Z" +
"**** 166.57 5Z" +
"**** 42.56 9Z" +
"**** 81.90 95Z" +
"**** 131.78 8Z" +
"**** 255.89 78Z" +
"**** 109.17 9Z" +
"**** 146.69 68Z" +
"**** 139.33 65Z" +
"**** 141.16 78Z" +
"**** 154.74 8Z" +
"**** 59.42 8Z" +
"**** 85.44 68Z" +
"**** 293.70 88Z" +
"**** 261.79 65Z" +
"**** 11.30 88Z" +
"**** 268.27 58Z" +
"**** 128.29 88Z" +
"**** 251.03 8Z" +
"**** 208.39 75Z" +
"**** 128.88 75Z" +
"**** 62.06 9Z" +
"**** 225.87 75Z" +
"**** 12.89 75Z" +
"**** 34.28 75Z" +
"**** 62.16 58Z" +
"**** 129.12 5Z" +
"**** 218.37 5Z" +
"**** 289.69 8Z ";
int lineNum = 0; //統(tǒng)計(jì)有多少個(gè)商品
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i)=='*') lineNum++;
}
lineNum/=4;
double prices[] = new double[lineNum];
double discount[] = new double[lineNum];
String newStrP=new String();
String newStrD=new String();
int prn=0;
int din=0;
for(int i = 0; i < str.length(); i++) {
if((str.charAt(i) >= '0' && str.charAt(i) <= '9') || str.charAt(i)=='.') {
if (str.charAt(i+1)=='Z' || str.charAt(i+2)=='Z') {
if (!newStrP.equals("")) {
//System.out.println(Double.valueOf(newStrP));
prices[prn] = Double.valueOf(newStrP);
prn++;
}
newStrP=new String();
continue;
}
newStrP+=str.charAt(i);
}
}
for(int i = 0; i < str.length(); i++) {
if((str.charAt(i) >= '0' && str.charAt(i) <= '9')) {
if (!(str.charAt(i+1)=='Z' || str.charAt(i+2)=='Z')) {
if (!newStrD.equals("")) {
//System.out.println(Double.valueOf(newStrP));
discount[din] = Double.valueOf(newStrD);
din++;
}
newStrD=new String();
continue;
}
newStrD+=str.charAt(i);
}
}
prn = 0;
din = 0;
//
// for(double e:prices) {
// System.out.println(e);
// }
// for(double e:discount) {
// System.out.println(e);
// }
//
//
for(;prn<prices.length;prn++) {
prices[prn] *=CouDis(discount[prn]);
}
double result=0;
for(double e:prices) {
result+=e;
}
System.out.print(result);
}
}