Created
March 26, 2020 20:52
-
-
Save bastienapp/be4527b0647d981a0ce113c80d816cd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******* | |
* Read input from System.in | |
* Use: System.out.println to ouput your result to STDOUT. | |
* Use: System.err.println to ouput debugging information to STDERR. | |
* ***/ | |
package com.isograd.exercise; | |
import java.util.*; | |
public class IsoContest { | |
public static void main( String[] argv ) throws Exception { | |
String line; | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
String[] choices = new String[n]; | |
for (int i = 0; i < n; i++) { | |
String c = sc.next(); | |
choices[i] = c; | |
} | |
String color1 = ""; | |
int max1 = 0; | |
for (String c : choices) { | |
int count = 0; | |
for (String o : choices) { | |
if (c.equals(o)) { | |
count++; | |
} | |
} | |
if (count > max1) { | |
max1 = count; | |
color1 = c; | |
} | |
} | |
String color2 = ""; | |
int max2 = 0; | |
for (String c : choices) { | |
if (!c.equals(color1)) { | |
int count = 0; | |
for (String o : choices) { | |
if (c.equals(o)) { | |
count++; | |
} | |
} | |
if (count > max2) { | |
max2 = count; | |
color2 = c; | |
} | |
} | |
} | |
System.out.println(color1 + " " + color2); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******* | |
* Read input from System.in | |
* Use: System.out.println to ouput your result to STDOUT. | |
* Use: System.err.println to ouput debugging information to STDERR. | |
* ***/ | |
package com.isograd.exercise; | |
import java.util.*; | |
public class IsoContest { | |
public static void main( String[] argv ) throws Exception { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
int prev = -1; | |
int s = -1; | |
int c = 1; | |
for (int i = 0; i < n; i++) { | |
int v = sc.nextInt(); | |
if (v == prev) { | |
c++; | |
} | |
if (v != prev || i == n - 1) { | |
if (c > s) { | |
s = c; | |
} | |
prev = v; | |
c = 1; | |
} | |
} | |
System.out.println(s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment