https://www.hackerrank.com/challenges/repeated-string/problem
#include<stdio.h>
int main()
{
char str[120];
scanf("%s",str);
unsigned long long int len,c=0,rep,i,rem;
scanf("%llu",&len);
for(i=0;str[i]!='\0';i++)
if(str[i]== 'a')
c++;
//number of times string can be repeated
rep=len/i;
rem=len%i;
c=c*rep;
for(i=0;i<rem;i++)
if(str[i] == 'a')
c++;
printf("%llu",c);
}
No comments:
Post a Comment