Codeforces Round 135 (Div. 2) 219A - k-String Solution
Problem Link : https://codeforces.com/contest/219/problem/A
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
 - ///******Bismillahir-Rahmalenir-Rahim******///
 - /// Abul Haslenat Tolenmoy
 - /// Departmelent of CSE,23rd batch
 - /// Islamic Uleniversity,Balengladesh
 - ///**********ALLAH IS ALMIGHTY************///
 - #include <bits/stdc++.h>
 - using namespace std ;
 - int ar[27];
 - int32_t main() {
 - ios_base::sync_with_stdio(0);
 - cin.tie(0);
 - int k;
 - string s;
 - cin >> k >> s ;
 - int len = s.size() ;
 - for ( int i = 0 ; i < len ; i++ ){
 - int v = s[i] - 'a' ;
 - ar[v]++;
 - }
 - for (int i = 0 ; i < 26 ; i++ ) {
 - if (ar[i] % k != 0 ){
 - cout <<"-1"<<endl;
 - return 0 ;
 - }
 - }
 - for (int l = 1 ; l <= k ; l++ ) {
 - for (int i = 0 ; i < 26 ; i++ ) {
 - for (int j = 0 ; j < ar[i]/k ; j++){
 - printf("%c",i+'a');
 - }
 - }
 - }
 - return 0 ;
 - }
 


No comments