-
Notifications
You must be signed in to change notification settings - Fork 0
/
RepeatedString.java
52 lines (52 loc) · 1.39 KB
/
RepeatedString.java
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
package practicetime;
import java.util.*;
public class RepeatedString
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
//System.out.println(s.length());
int count=0,c=0;
long n=sc.nextLong();
long d=Math.abs(n-s.length());
//System.out.println(d);
if(s.length()>n){
for(int i=0;i<n;i++)
{
if(s.charAt(i)=='a')
{
count++;
}
}System.out.println(count);}
else{
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='a')
{
count++;
}
}
//System.out.println(count);
long r=d%s.length();
//System.out.println(" r "+r);
//System.out.println(r);
if(r==0)
{
System.out.println(count*(n/s.length()));
}
else if(r!=0)
{
for(long i=0;i<r;i++)
{
if(s.charAt((int)i)=='a')
{
c++;
}
}
System.out.println(count*(n/s.length())+c);
}
}}
}
//udjlitpopjhipmwgvggazhuzvcmzhulowmveqyktlakdufzcefrxufssqdslyfuiahtzjjdeaxqeiarcjpponoclynbtraaawrps
//872514961806 69801196944