Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:感觉对的代码AC不了,感觉错的代码却AC了,真郁闷In Reply To:感觉对的代码AC不了,感觉错的代码却AC了,真郁闷 Posted by:yunyifly at 2007-05-30 21:03:07 刚开始用float写,两个都AC不了,检查了半天,最后用double就过了。 如果照我说的加个ceil的话过不了,感觉这题的数据有问题。 > 这是AC的代码。 > #include<iostream> > #include<cmath> > using namespace std; > > int main() > { > int card[600]; > double sum=0; > int temp=0; > int pretemp=0; > int i=2; > while(sum<5.21) > { > sum+=(1/double(i)); > pretemp=temp+1; > temp=sum*100; > for(int j=pretemp;j<=temp;j++) > { > card[j]=i-1; > } > i++; > } > cin>>sum; > while(sum>0.001) > { > > cout<<card[int(sum*100)]<<" card(s)"<<endl; > //感觉上面这句应该改成cout<<card[int(ceil(sum*100))]<<" card(s)"<<endl; > cin>>sum; > } > return 0; > } > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator