You are viewing a single comment's thread. Return to all comments →
Nice, but it can be done with a single loop:
public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); long n = in.nextLong(); if (!s.contains("a")) { System.out.println(0); return; } long count = 0; long mod = s.length() > 0 ? n % s.length() : 0; long remainder = 0; boolean strLonger = false; for (int i = 0; i < s.length(); ++i) { if (i >= n) { strLonger = true; break; } if (s.charAt(i) == 'a') { if (mod > i) remainder++; count++; } } if (!strLonger) count = count * Math.max(n / s.length(), 1) + remainder; System.out.println(count); }
Seems like cookies are disabled on this browser, please enable them to open this website
Repeated String
You are viewing a single comment's thread. Return to all comments →
Nice, but it can be done with a single loop: