1+ package hackerRank_JavaProblemSolving ;
2+
3+ import java .io .BufferedWriter ;
4+ import java .io .FileWriter ;
5+ import java .io .IOException ;
6+ import java .util .Scanner ;
7+
8+ public class Problem060_ACMICPC_ORonArrayOfStrings {
9+
10+ public static int getSizeOf1BitAfterORon2Strs (String a , String b , int size ) {
11+ int sumBit = 0 ;
12+ for (int i = 0 ; i < size ; i ++) { // assumption that two string has the same size
13+ if (a .charAt (i ) == '1' || b .charAt (i ) == '1' ) {
14+ sumBit ++;
15+ }
16+ }
17+ return sumBit ;
18+ } // getSizeOf1BitAfterORon2Strs
19+
20+ static int [] acmTeam (String [] topic ) {
21+ int size = topic [0 ].length (); // a one string size
22+ int len_arr = topic .length ;
23+ int maxSizeOf1BitInORSumStr = 0 ;
24+ int counterOfSuchStrs = 0 ;
25+ for (int i = 0 ; i < len_arr -1 ; i ++ ) {
26+ for (int j = i +1 ; j < len_arr ; j ++ ) {
27+ int twoStrsRes = getSizeOf1BitAfterORon2Strs (topic [i ],topic [j ],size );
28+ if ( twoStrsRes > maxSizeOf1BitInORSumStr ) { // new record
29+ maxSizeOf1BitInORSumStr = twoStrsRes ;
30+ counterOfSuchStrs = 1 ;
31+ }
32+ else if (twoStrsRes == maxSizeOf1BitInORSumStr ) {
33+ counterOfSuchStrs ++;
34+ }
35+ } // for pairs' forming
36+ }
37+ int [] res = {maxSizeOf1BitInORSumStr , counterOfSuchStrs };
38+ return res ;
39+ }
40+
41+ private static final Scanner scanner = new Scanner (System .in );
42+
43+ public static void main (String [] args ) throws IOException {
44+ BufferedWriter bufferedWriter = new BufferedWriter (new FileWriter (System .getenv ("OUTPUT_PATH" )));
45+
46+ String [] nm = scanner .nextLine ().split (" " );
47+
48+ int n = Integer .parseInt (nm [0 ]);
49+
50+ String [] topic = new String [n ];
51+
52+ for (int i = 0 ; i < n ; i ++) {
53+ String topicItem = scanner .nextLine ();
54+ topic [i ] = topicItem ;
55+ }
56+
57+ int [] result = acmTeam (topic );
58+
59+ for (int i = 0 ; i < result .length ; i ++) {
60+ bufferedWriter .write (String .valueOf (result [i ]));
61+
62+ if (i != result .length - 1 ) {
63+ bufferedWriter .write ("\n " );
64+ }
65+ }
66+
67+ bufferedWriter .newLine ();
68+
69+ bufferedWriter .close ();
70+
71+ scanner .close ();
72+ }
73+
74+ } // Problem060_ACMICPC_ORonArrayOfStrings
0 commit comments