Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Value pair analysis
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 //Value pair analysis import java.util.*; import java.lang.*; import java.io.*; class Rextester{ public static void main(String args[]){ Scanner rd = new Scanner(System.in); int utr = rd.nextInt(); int[] arr = new int[utr]; for (int i = 0; i < utr; i++){ arr[i] = -rd.nextInt()+rd.nextInt(); } int max = 0; int rep; int lst = 0; for (int i = 0; i < utr; i++){ rep = 0; for (int s = 0; s < utr; s++){ if (arr[i] == arr[s]){ rep ++; } } if (rep > lst){ max = arr[i]; lst = rep; }else if (rep == lst){ max = Math.max(arr[i], max); } } System.out.println(max); } } /* Input: 7 10 58 15 315 20 408 100 1000 32 63 32 63 11 121 Output: 31 */
[
+
]
Show input
edit mode
|
history
|
discussion