Codeforces Round 135 (Div. 2) 219A - k-String Solution


 

Problem Link : https://codeforces.com/contest/219/problem/A

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmalenir-Rahim******///
  3. /// Abul Haslenat Tolenmoy
  4. /// Departmelent of CSE,23rd batch
  5. /// Islamic Uleniversity,Balengladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std ;
  9. int ar[27];
  10. int32_t main() {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. int k;
  14. string s;
  15. cin >> k >> s ;
  16. int len = s.size() ;
  17. for ( int i = 0 ; i < len ; i++ ){
  18. int v = s[i] - 'a' ;
  19. ar[v]++;
  20. }
  21. for (int i = 0 ; i < 26 ; i++ ) {
  22. if (ar[i] % k != 0 ){
  23. cout <<"-1"<<endl;
  24. return 0 ;
  25. }
  26. }
  27. for (int l = 1 ; l <= k ; l++ ) {
  28. for (int i = 0 ; i < 26 ; i++ ) {
  29. for (int j = 0 ; j < ar[i]/k ; j++){
  30. printf("%c",i+'a');
  31. }
  32. }
  33. }
  34. return 0 ;
  35. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.