[URI Online Judge] – 1080 – Highest and Position

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.

Sample Input Sample Output
2
113
45
34565
6

8
34565
4

Solution:

#include <cstdio>
int main(){
 int n, q = 0, g = -1, i = -1;
 while(++q && q <= 100){
 scanf("%d", &n);
 if (n > g){
 g = n; i = q;
 }
}
 printf("%d\n", g);
 printf("%d\n", i);
 return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s