PAT Advanced Level 1011(Java and C++)

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);
	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值