Files

37 lines
1.0 KiB
Java

// Author: Rodney Shaghoulian
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
String str = scan.next();
long n = scan.nextLong();
scan.close();
/* Found out # of times 'a' appears in our String */
int wordAs = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'a') {
wordAs++;
}
}
long completeWords = n / str.length();
long remainingLetters = n % str.length();
long totalAs = completeWords * wordAs;
/* Count up the remaining 'a' characters */
for (int i = 0; i < remainingLetters; i++) {
if (str.charAt(i) == 'a') {
totalAs++;
}
}
System.out.println(totalAs);
}
}