Friday, 14 October 2016

Repeated String Hacker Rank Problem Solution.


Solution:


#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() { string str; long long n,cnt = 0,rem,rept,remCnt = 0; cin >> str; cin >> n; long long len = str.length(); rem = n%len; rept = n/len; for(int i = 0; i < len; i++){ if(str[i] == 'a')cnt++; if(str[i] == 'a' && i < rem)remCnt++; } cout << (cnt*rept)+remCnt << endl; return 0; }

No comments:

Post a Comment