題目如下圖,左邊的代碼是我自己寫的,錯誤率83%,然后右邊的代碼是我參考別的大佬的代碼更改之后的,兩段代碼只有綠框中不一樣。。。。我很想知道我自己的代碼到底錯在哪。。自己測驗了好幾次都沒發現錯誤。。


uj5u.com熱心網友回復:
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 610;
double r[610];
bool cmp(double x,double y)
{
return x>y;
}
double count(double p)
{
double t;
t=2*sqrt(p*p-1*1);
return t;
}
int main()
{
int m,n,i,c;
double len;
scanf("%d",&m);
while(m--)
{
scanf("%d",&n);
for(i=0;i<n;++i)
scanf("%lf",&r);
sort(r,r+n,cmp);
len=0;
c=0;
for(i=0;i<n;++i)
{
len+=count(r[i]);
c++;
if(len>=20) break;
}
printf("%d\n",c);
}
return 0;
}
[i]這樣便是
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/100330.html
標籤:新手樂園
下一篇:c++xlnt庫怎么讀中文
