Algorithm


Problem Name: beecrowd | 1080
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1080

Highest and Position

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Read 100 integer numbers. Print the highest read value and the input position.

Input

The input file contains 100 distinct positive integer numbers.

Output

Print the highest number read and the input position of this value, according to the given example.

Input Sample Output Sample

2
113
45
34565
6
...
8
 

34565
4

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main()
{
    int n, max = -1, p, i;
    for (i = 1; i  <  101; ++i)
    {
        scanf("%d", &n);
        if(max < n)
        max = n, p = i;
    }

    printf("%dn%dn", max, p>;

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 113 45 34565 6 ... 8

Output

x
+
cmd
34565 4

#2 Code Example with C++ Programming

Code - C++ Programming


#include <stdio.h>

int main(int argc, char const *argv[])
{
    int n, max = -1, p;
    for (int i = 1; i  <  101; ++i)
    {
        scanf("%d", &n);
        if(max < n)
        max = n, p = i;
    }

    printf("%dn%dn", max, p>;

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 113 45 34565 6 ... 8

Output

x
+
cmd
34565 4

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        int N =100, X, highest = 0,position = 0;
        Scanner input =new Scanner(System.in);
        for (int i = 1; i  < = N; i++)
        {
            X =input.nextInt();

            if (highest > X)
            {
                highest = highest;
                position = position;
            }
            else
            {
                highest = X;
                position = i;
            }

        }
        System.out.print(highest+"n"+position+"n");
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 113 45 34565 6 ... 8

Output

x
+
cmd
34565 4

#4 Code Example with Python Programming

Code - Python Programming


j=0
loc=0
for i in range(100):
    n=int(input())
    if(n>j):
        j=n
        loc=i
print(j)
print(loc+1)
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 113 45 34565 6 ... 8

Output

x
+
cmd
34565 4
Advertisements

Demonstration


Previous
#1079 Beecrowd Online Judge Solution 1079 Weighted Averages - Solution in C, C++, Java, Python and C#
Next
#1081 Beecrowd Online Judge Solution 1081DFSr - Depth Hierarchy - Solution in C, C++, Java, Python and C#