Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:木棒程序的编程c++

Posted by sc071139 at 2012-01-22 15:18:50 on Problem 1011
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator