#31231: 求救!第三測資過不了


Super487 (Super487)

學校 : 國立交通大學
編號 : 182269
來源 : [140.113.92.29]
最後登入時間 :
2023-12-26 20:22:51
a647. 投資專家 | From: [111.248.102.209] | 發表日期 : 2022-07-19 20:09

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#define endl '\n'

int main() {
  int n;
  double a, b, ans;
  cin >> n;
  while(n--) {
    cin >> a >> b;
    ans = round((b-a)/a*10000)/100;
    cout<<fixed<<setprecision(2)<<ans<<"% ";
    if(ans>=10||ans<=-7)
      cout<<"dispose"<<endl;
    else
      cout<<"keep"<<endl;
  }
}

我已經用了其他人說的“先乘10000、求整數再除100“了,但還是沒辦法

 
#31310: Re: 求救!第三測資過不了


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a647. 投資專家 | From: [106.64.177.211] | 發表日期 : 2022-07-23 13:29

1.
    ans = round((b-a)/a*10000)/100;


2.

if(ans>=10||ans<=-7)


1. 先乘10000再除a

2. 你的ans是已經四捨五入的數字,這樣判斷會出錯

 
ZeroJudge Forum