You are viewing a single comment's thread. Return to all comments →
this is my solution
public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); long n = in.nextLong();
long numOfChar = 0 ; int numOfA = 0; int stringLength = s.length(); if(stringLength > 0){ for(int i=0;i<stringLength;i++){ if(s.charAt(i)=='a'){ numOfA++; } } long division = n / stringLength; long mod = n % stringLength; numOfChar = division * numOfA; for(int i=0;i<mod;i++){ if(s.charAt(i)=='a'){ numOfChar++; } } } System.out.println(numOfChar); }
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 →
this is my solution
public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); long n = in.nextLong();