VladimirGekov

Untitled

Nov 27th, 2019
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. int minLength(int n)
  2. {
  3. int ans = n / 26;
  4. if (n % 26 != 0)
  5. ans++;
  6.  
  7. return ans;
  8. }
  9.  
  10. // Function to find the minimum length String
  11. string minString(int n)
  12. {
  13. int ans = n / 26;
  14. string res = "";
  15.  
  16. while (ans--) {
  17. res = res + "z";
  18. }
  19.  
  20. if (n % 26 != 0) {
  21. res = res
  22. + (char)((n % 26) + 96);
  23. }
  24.  
  25. return res;
  26. }
  27.  
  28. // Driver code
  29. int main()
  30. {
  31. int n = 50;
  32.  
  33. cout << minLength(n)
  34. << endl
  35. << minString(n);
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment