-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
33 lines (23 loc) · 971 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Linq;
namespace Repeated_String {
class Program {
static long RepeatedString(string s, long n) {
long numberOfLettersInSubString = s.Count(c => c.Equals('a'));
if (numberOfLettersInSubString == 0) return 0;
long numberOfCompletedSubStrings = (long)(n / s.Length);
long frequencyOfFirstLetterInTheSubString = numberOfLettersInSubString * numberOfCompletedSubStrings;
int remainder = (int)(n % s.Length);
for (int i = 0; i < remainder; i++) {
if (s[i].Equals('a')) frequencyOfFirstLetterInTheSubString++;
}
return frequencyOfFirstLetterInTheSubString;
}
static void Main(string[] args) {
string s = Console.ReadLine();
long n = Convert.ToInt64(Console.ReadLine());
long result = RepeatedString(s, n);
Console.WriteLine(result);
}
}
}