Repeated String

 Question :-

https://www.hackerrank.com/challenges/repeated-string/problem

Solution in C language :-

#include<stdio.h>
#include<string.h>
int main(){
    long long int n;
    char s[100];
    scanf("%s %lld",s,&n);
    int len=strlen(s);
    long long int i,a=0;
    for(i=0;s[i]!='\0';i++){
        if(s[i]=='a')
            a++;
    }
    long long int t=n/len,temp=n%len;
    t=t*a;
    if(temp!=0){
        for(i=0;i<temp;i++){
            if(s[i]=='a')
                t++;
        }
    }
    printf("%lld",t);
    return 0;
}

Comments

Popular posts from this blog

Sherlock and Squares

Cut The Sticks

Home