Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Main {
- static int hjtthegreat(String s, int id, int cnt, boolean[] visited) {
- if (id + 1 > (int) s.length()) {
- return cnt;
- }
- if (s.charAt(id) == 'y' && s.charAt(id + 1) == 'o') {
- visited[id] = visited[id + 1] = true;
- if (id == 0 || s.charAt(id - 1) != 'o' || visited[id - 1]) {
- return hjtthegreat(s, id + 1, cnt + 1, visited);
- }
- }
- return hjtthegreat(s, id + 1, cnt, visited);
- }
- public static void main(String[] args) {
- String[] s = {"ayoxyoxyoxyoxyo", "ayobyoayobhadjipogiyoayobyo",
- "xyoxhadjiohiyoyoyo", "yoyooyoxhadjiohioyooyoyoxxyoyo"};
- int id = 0;
- int cnt = 0;
- boolean[] visited;
- for (int i = 0; i < (int) s.length; i++) {
- visited = new boolean[(int) s[i].length()];
- Arrays.fill(visited, false);
- System.out.println(s[i] + (i % 2 == 0 ? "=" : ":") + hjtthegreat(s[i], id, cnt, visited));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment