Files

37 lines
1.0 KiB
Java
Raw Permalink Normal View History

2017-03-10 01:10:37 -06:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-03-10 01:10:37 -06:00
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++;
}
}
2017-04-05 18:42:35 -05:00
2017-03-10 01:10:37 -06:00
long completeWords = n / str.length();
2017-04-05 18:42:35 -05:00
long remainingLetters = n % str.length();
long totalAs = completeWords * wordAs;
2017-03-10 01:10:37 -06:00
2017-04-05 18:42:35 -05:00
/* Count up the remaining 'a' characters */
2017-03-10 01:10:37 -06:00
for (int i = 0; i < remainingLetters; i++) {
if (str.charAt(i) == 'a') {
totalAs++;
}
}
2017-04-05 18:42:35 -05:00
2017-03-10 01:10:37 -06:00
System.out.println(totalAs);
}
}