1009 - 外币兑换
时间限制 : 1 秒
内存限制 : 32 MB
小明刚从美国回来,发现手上还有一些未用完的美金,于是想去银行兑换成人民币。可是听说最近人民币将会升值,并从金融机构得到了接下来十二个月可能的美元对人民币汇率,现在,小明想要在接下来一年中把美金都兑换成人民币,请问最多能得到多少人民币?
题目输入
输入的第一行是一个实数N(1.00<=N<=100.00),表示小明现有的美金数量。
接下来一行,包含12个实数ai,表示接下来十二个月的美元对人民币汇率。
题目输出
输出一个小数R,表示小明最多能获得的人民币数量,结果保留两位小数。
输入/输出样例
输入格式
46.91 6.31 6.32 6.61 6.65 5.55 5.63 6.82 6.42 6.40 5.62 6.78 5.60
输出格式
319.93
C语言解答
#include<stdio.h> int main() { double n,a[12],max; int i; scanf("%lf",&n); for(i=0;i<12;i++) scanf("%lf",&a[i]); max=a[0]; for(i=1;i<12;i++) if(max<a[i]) max=a[i]; printf("%.2lf\n",n*max); return 0; }
C++解答
#include <stdio.h> int main() { float money; while(scanf("%f",&money)!=EOF) { float change; float max=0; for(int i=0;i<12;i++) { scanf("%f",&change); if(max<change) max=change; } printf("%.2f\n",max*money); } return 0; }
Java解答
import java.util.Scanner; public class Main { //转换int成为ascii码值 /* public static char toChar(int prefix){ return (char) prefix; } */ //输入整型 /* public static int scanfInt(){ @SuppressWarnings("resource") Scanner sc = new Scanner(System.in); return sc.nextInt(); } */ //输入float /* public static float scanfFloat(){ @SuppressWarnings("resource") Scanner sc = new Scanner(System.in); return sc.nextFloat(); } */ //判断字符c是否在set中 /* public static boolean isInSet(char c){ if(c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'F'){ return true; } else return false; } */ /* public static String judgeEdition(int i){ if(i == 0) return "Same"; else if(i == 1) return "First"; else return "Second"; } */ /* //版本号相等 if(edition[i][0][0] == edition[i][1][0]){ //子版本号相等 if(edition[i][0][1] == edition[i][1][1]){ //修订号相等 if(edition[i][0][2] == edition[i][1][2]){ result[i] = 0; } //第一个修订号大 else if(edition[i][0][2] > edition[i][1][2]){ result[i] = 1; } //第二个修订号大 else result[i] = 2; } //子版本号第一个大 else if(edition[i][0][1] > edition[i][1][1]){ result[i] = 1; } //子版本号第二个大 else result[i] = 2; } //版本号第一个大 else if(edition[i][0][0] > edition[i][1][0]){ result[i] = 1; } //版本号第二个大 else result[i] = 2; */ public static void main(String[] args){ @SuppressWarnings("resource") Scanner sc = new Scanner(System.in); float[] rate = new float[12]; float money = sc.nextFloat(); float most = 0; for(int i=0;i<12;i++){ rate[i] = sc.nextFloat(); if(money*rate[i] > most){ most =money * rate[i]; } } System.out.println(String.format("%.2f", most)); } }
Python解答
import sys for line in sys.stdin: a = line.split() b = map(lambda x:float(x),a) if len(b) == 1: m = b[0] if len(b) != 1: print round(m*max(b),2)