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:木棒程序的编程c++In Reply To:木棒程序的编程c++ Posted by:miji90000 at 2011-01-23 23:22:37 你这个程序只能解一组数据,而且不过精确, 5 5 4 4 2 1这组数据你就过不了,你输出6但是答案是8. 再者说,应该把主函数改为int型,最后末尾return 0; 按你的写法,应写成以下这样 #include<iostream.h> using namespace std; int main() { int i,n,a[64],max,min; cin>>n; for(i=0;i<n;i++) {cin>>a[i];} max=a[0];min=a[n-1]; for(i=0;i<n;i++) { if(a[i]>max) max=a[i]; } for(i=0;i<n;i++) { if(a[i]<min) min=a[i]; } cout<<max+min; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator