1501110016-Waterloo Cup-algorithm training to find the maximum value of __ algorithm in the array

Source: Internet
Author: User
Algorithm training to find the maximum time limit of the array: 1.0s memory limit: 512.0MB problem description for the given integer array a[], look for the maximum value, and return subscript. Input format integer array a[], the number of array elements is less than 1 equals 100. The output data is divided into two lines: the first row has only one number, representing the number of array elements, and the elements of the second behavior array. Output format output maximum value, and its subscript sample input 33 2 1 sample output 3 0 Solving ideas First assign value max=num[0],maxw=0, then the edge input edge to judge the change. Java code
Package looking for the maximum value in the array;
Import Java.util.Scanner;
public class Main
{public
	static void Main (string[] args)
	{
		Scanner input=new Scanner (system.in);
		int N=input.nextint ();
		Int[] Num=new int[n];
		Num[0]=input.nextint ();
		int max,maxw;
		MAX=NUM[0];
		maxw=0;
		for (int i=1;i<n;i++)
		{
			num[i]=input.nextint ();
			if (Max<num[i])
			{
				max=num[i];
				Maxw=i
			}
		}
		System.out.println (max+ "" +maxw);
	}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.