-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
62 lines (47 loc) · 783 Bytes
/
main.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
long
repeatedString(string s, long n)
{
long count=0;
for (long i=0; i < s.size(); i++)
{
if (s[i]=='a')
count+=1;
}
long mult = n/s.size();
int diff = n%s.size();
count*=mult;
for (long i=0; i < diff; i++)
{
if (s[i]=='a')
count+=1;
}
return count;
}
int
main(int argc, char **argv)
{
if (argc==1)
return 0;
ifstream filein (argv[1]);
string line;
string s;
long n;
if (filein.is_open())
{
getline ( filein, line );
s = line;
getline ( filein, line );
n = stol(line);
filein.close();
}
else
{
cout << "Unable to open file";
return 0;
}
long result = repeatedString(s,n);
cout << result << "\n";
return 0;
}