#24709: for JAVA


SoulOfNag (拿各之魂)

學校 : 不指定學校
編號 : 39223
來源 : [59.124.121.61]
最後登入時間 :
2024-05-06 13:13:50
a647. 投資專家 | From: [209.234.248.246] | 發表日期 : 2021-03-16 18:22

%數和英文狀態 要分開判斷

以下是我的code:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
public class A647_10{
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		String numStr;
		String[] strArray;
		BigDecimal rs,rs2;
		int i,killDot;
		int n=Integer.parseInt(str);
		double hasDot;
		for(i=0;i<n;i++){
			str=br.readLine();
			strArray=str.split(" ");
			rs=((new BigDecimal(strArray[1]).subtract(new BigDecimal(strArray[0]))).multiply(new BigDecimal(100))).divide(new BigDecimal(strArray[0]),3,BigDecimal.ROUND_DOWN);
			rs2=rs;
			numStr=rs.toString();
			if(Integer.parseInt(numStr.substring(numStr.length()-1,numStr.length()))>4){
				if(rs.compareTo(new BigDecimal(0))==1){
					rs=(rs.add(new BigDecimal(0.01))).divide(new BigDecimal(1),3,BigDecimal.ROUND_DOWN);
				}else if(rs.compareTo(new BigDecimal(0))==-1){
					rs=(rs.subtract(new BigDecimal(0.01))).divide(new BigDecimal(1),3,BigDecimal.ROUND_DOWN);
				}
				numStr=rs.toString();
			}
			numStr=numStr.substring(0,numStr.length()-1);
			hasDot=new Double(numStr);
			killDot=(int)hasDot;
			if(killDot>=10||killDot<=-7){
				System.out.print(numStr+"% ");
			}else{
				System.out.print(numStr+"% ");
			}
			if(rs2.compareTo(new BigDecimal(10))==0||rs2.compareTo(new BigDecimal(10))==1||rs2.compareTo(new BigDecimal(-7))==0||rs2.compareTo(new BigDecimal(-7))==-1){
				System.out.println("dispose");
			}else{
				System.out.println("keep");
			}
    		}
  	}
}
 
ZeroJudge Forum