-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unfinished
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,52 @@ | ||
|
||
/* | ||
ID: lllgoyo2 | ||
LANG: JAVA | ||
TASK: beads | ||
*/ | ||
import java.io.*; | ||
|
||
public class beads { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader in = new BufferedReader(new FileReader("beads.in")); | ||
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("beads.out"))); | ||
|
||
int n = Integer.parseInt(in.readLine()); | ||
String beads = in.readLine(); | ||
in.close(); | ||
|
||
int maxBeads = 0; | ||
for (int i = 0; i < n; i ) { | ||
int leftCount = countBeads(beads, i, -1); | ||
int rightCount = countBeads(beads, i, 1); | ||
maxBeads = Math.max(maxBeads, leftCount rightCount); | ||
} | ||
|
||
out.println(maxBeads); | ||
out.close(); | ||
} | ||
|
||
private static int countBeads(String necklace, int startIndex, int direction) { | ||
int count = 0; | ||
char color = 'w'; // Initial color is white | ||
|
||
int currentIndex = startIndex; | ||
while (count < necklace.length()) { | ||
int nextIndex = (currentIndex direction necklace.length()) % necklace.length(); | ||
char currentColor = necklace.charAt(currentIndex); | ||
|
||
if (currentColor != 'w') { | ||
if (color == 'w') { | ||
color = currentColor; | ||
} else if (currentColor != color) { | ||
break; // Different color encountered, stop counting | ||
} | ||
} | ||
|
||
count ; | ||
currentIndex = nextIndex; | ||
} | ||
|
||
return count; | ||
} | ||
} |