-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy patharya's long string
More file actions
87 lines (70 loc) · 1.44 KB
/
arya's long string
File metadata and controls
87 lines (70 loc) · 1.44 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
Arya has a string, S, of uppercase English letters. She writes down the string S on a paper K times.
She wants to calculate the occurence of a specific letter in the first N characters of the final string.
Input:
First line of input contains a single integer T denoting the number of test cases.
The first line of each test case contains a string S.
The second line contains 2 space-separated integers K and N, and an uppercase English letter C whose occurence needs to be counted.
Output:
For each test case, print the required answer in a new line.
Constraints:
1 <= T <= 150
1 <= |S| <= 500
1 <= K <= 10^5
1 <= N <= |S|*K
Example:
Input :
2
ABA
3 7 B
BHD
4 6 E
Output :
2
0
Explaination :
Case 1 : Final string - ABAABAABA
Case 2 : Final string - BHDBHDBHDBHD
Example 2 :
Input :
1
MMM
2 4 M
Output :
4
Explaination :
Case 1 : Final string - MMMMMM
*/
#include <iostream>
using namespace std;
long long occ(string s, int n, char c)
{
int count=0;
for(int i=0; i<n; i++)
{
if(s[i]==c) count++;
}
return count;
}
int main() {
int t; cin>>t; while(t--)
{
string s; cin>>s;
long long r,f; cin>>r>>f;
char p; cin>>p;
long long n=s.size();
if(f%n == 0)
{
cout<<occ(s,n,p)*(f/n)<<endl;
}
else
{
long long q=f/n;
long long sum=q*occ(s,n,p);
long long q1=f%n;
sum= sum + occ(s,q1,p);
cout<<sum<<endl;
}
}
return 0;
}