2013
11-13

# Exchange Rates

Now that the Loonie is hovering about par with the Greenback, you have decided to use your \$1000 entrance scholarship to engage in currency speculation. So you gaze into a crystal ball which predicts the closing exchange rate between Canadian and U.S. dollars for each of the next several days. On any given day, you can switch all of your money from Canadian to U.S. dollars, or vice versa, at the prevailing exchange rate, less a 3% commission, less any fraction of a cent.

Assuming your crystal ball is correct, what’s the maximum amount of money you can have, in Canadian dollars, when you’re done?

The input contains a number of test cases, followed by a line containing 0. Each test case begins with 0 < d ≤ 365, the number of days that your crystal ball can predict. d lines follow, giving the price of a U.S. dollar in Canadian dollars, as a real number.

For each test case, output a line giving the maximum amount of money, in Canadian dollars and cents, that it is possible to have at the end of the last prediction, assuming you may exchange money on any subset of the predicted days, in order.

3
1.0500
0.9300
0.9900
2
1.0500
1.1000
0


1001.60
1000.00

//* @author:
import java.util.*;
public   class Main{

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);

int i,n;
double rate,us,ca,tus,tca,t1,t2;
while (sc.hasNext()) {
n=sc.nextInt();
if(n==0) break;
ca=1000;us=0;
for (i=1;i<=n;i++) {
rate=sc.nextDouble();
t1=ca/rate*.97;
t1=(Math.floor(t1*100))/100;
t2=us*rate*.97;
t2=(Math.floor(t2*100))/100;
tus=(us>t1?us:t1);
tca=(ca>t2?ca:t2);
us=tus;ca=tca;
}
System.out.printf("%.2f\n",ca);
}
}

}

1. 第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。

2. 这道题目虽然简单，但是小编做的很到位，应该会给很多人启发吧！对于面试当中不给开辟额外空间的问题不是绝对的，实际上至少是允许少数变量存在的。之前遇到相似的问题也是恍然大悟，今天看到小编这篇文章相见恨晚。

3. 这道题目的核心一句话是：取还是不取。
如果当前取，则index+1作为参数。如果当前不取，则任用index作为参数。