Monday, March 28, 2016

URI 1180 solution in java language

URI Online Judge | 1180

Lowest Number and Position

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1

Write a program that reads a number N. This is the size of a array X[N]. Next, read each of the numbers of X, find the smallest element of this array and its position within the array, printing this information.

Input

The first line of input contains one integer (1 < <1000), indicating the number of elements that should be read to an array X[N] of integer numbers. The second row contains each of the N values, separated by a space.

Output

The first line displays the message “Menor valor:” followed by a space and the lowest number read in the input. The second line displays the message “Posicao:” followed by a space and the array position in which the lowest number is, remembering that the array starts at the zero position.
Input SampleOutput Sample
10
1 2 3 4 -5 6 7 8 9 10
Menor valor: -5
Posicao: 4


Solution in java language :

package uri_java_problem_solution;

/**
10

1 2 3 4 -5 6 7 8 9 10

Menor valor: -5

Posicao: 4

**/



import java.util.Scanner;



public class URI_1180 {

    public static void main(String[] args){

        int n,min = 0,tmpmMin = 0, position = 0;

        boolean checkFirst = false;

        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();

        int array[] = new int[n];

        //take the value for array

        for (int i = 0; i < n; i++) {

            array[i] = sc.nextInt();

        }



        for (int j = 0; j < n; j++) {

            tmpmMin = array[j];

            if (checkFirst == false) {

                min = tmpmMin;

                checkFirst = true;

            }

            if (tmpmMin < min) {

                min = tmpmMin;

                position = j;

            }

        }

        System.out.print("Menor valor: "+min+"\nPosicao: "+position+"\n");

    }
}



No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.