您的位置:首页 > 编程语言 > C语言/C++

PAT Advanced Level 1011(Java and C++)

2014-09-01 22:42 375 查看
C++

#include <iostream>
#include <stdio.h>
using namespace std;

float maxF(float w ,float t ,float l){
if(w>= t && w>=l){
printf("W ");
return w;
}
else if(t>= w && t>=l){
printf("T ");
return t;
}
else{
printf("L ");
return l;
}
}

int main()
{
float w,t,l,profit =1;

for(int i=0;i<3;i++){
scanf("%f%f%f",&w,&t,&l);
profit *= maxF(w,t,l);
}
profit = (profit*0.65 -1)*2;
printf("%.2f",profit);
return 0 ;
}


Java

import java.util.Scanner;

public class Main {

public static String toWord(int a){
if(a == 0){
return "W";
}
else if(a==1){
return "T";
}
else{
return "L";
}
}

public static void main(String[] arg){
Scanner sc  = new Scanner(System.in);
String[] arr1 =sc.nextLine().trim().split(" ");
String[] arr2 =sc.nextLine().trim().split(" ");
String[] arr3 =sc.nextLine().trim().split(" ");
int maxInx1=0 , maxInx2 =0,maxInx3=0;
double max1 =0 ,max2=0 ,max3=0;
for(int i=0;i<3;i++){
double a1 ,a2 ,a3;
a1 = Double.parseDouble(arr1[i]);
a2 = Double.parseDouble(arr2[i]);
a3 = Double.parseDouble(arr3[i]);
if(a1>max1){
max1 = a1;
maxInx1 =i;
}
if(a2>max2){
max2 = a2;
maxInx2 =i;
}
if(a3>max3){
max3 = a3;
maxInx3 =i;
}
}

System.out.print(toWord(maxInx1)+" ");
System.out.print(toWord(maxInx2)+" ");
System.out.print(toWord(maxInx3)+" ");
double result =(max1*max2*max3*0.65-1)*2;
result  =(double)Math.round(result*100)/100;
System.out.println(result);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: