#16487: 請問這個哪裡錯??謝謝 他最後NA


fdhs10838030 (巫以瑄)


#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
{
double a,b;
cin>>a>>b;
double x;
x=a>b?(a-b):(b-a);
double y;
y=x/a*100;
if(a>b)
{
if(y>=7)
{
cout<<"-"<<fixed<<setprecision(2)<<y;
cout<<"% dispose"<<endl;
}
else
{
cout<<" -"<<fixed<<setprecision(2)<<y;
cout<<"% keep"<<endl;
}
}
else
{
if(y>=10)
{
cout<<fixed<<setprecision(2)<<y;
cout<<"% dispose"<<endl;
}
else
{
cout<<" "<<fixed<<setprecision(2)<<y;
cout<<"% keep"<<endl;
}
}
}
}
return 0;
}

#16488: Re:請問這個哪裡錯??謝謝 他最後NA


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)


#include
#include
using namespace std;
int main(){
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
{
double a,b;
cin>>a>>b;
double x;
x=a>b?(a-b):(b-a);
double y;
y=x/a*100;
if(a>b)
{
if(y>=7)
{
cout<<"-"<<fixed<<setprecision(2)<<y;
cout<<"% dispose"<<endl;
}
else
{
cout<<" -"<<fixed<<setprecision(2)<<y;
cout<<"% keep"<<endl;
}
}
else
{
if(y>=10)
{
cout<<fixed<<setprecision(2)<<y;
cout<<"% dispose"<<endl;
}
else
{
cout<<" "<<fixed<<setprecision(2)<<y;
cout<<"% keep"<<endl;
}
}
}
}
return 0;
}

#2: 50% WA (line:1)

您的答案為: 8.98% keep
正確答案為: 8.99% keep

應該是四捨五入的問題

#16490: Re:請問這個哪裡錯??謝謝 他最後NA


314159265358979323846264338327 ... (少年π)


#include
#include
using namespace std;
int main(){
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
{
double a,b;
cin>>a>>b;
double x;
x=a>b?(a-b):(b-a);
double y;
y=x/a*100;
if(a>b)
{
if(y>=7)
{
cout<<"-"<<fixed<<setprecision(2)<<y;
cout<<"% dispose"<<endl;
}
else
{
cout<<" -"<<fixed<<setprecision(2)<<y;
cout<<"% keep"<<endl;
}
}
else
{
if(y>=10)
{
cout<<fixed<<setprecision(2)<<y;
cout<<"% dispose"<<endl;
}
else
{
cout<<" "<<fixed<<setprecision(2)<<y;
cout<<"% keep"<<endl;
}
}
}
}
return 0;
}

#2: 50% WA (line:1)

您的答案為: 8.98% keep
正確答案為: 8.99% keep

應該是四捨五入的問題

浮點數誤差