Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef unsigned long long ull;
  7. typedef long double ld;
  8.  
  9. const int INF = 1e9;
  10. const ll bINF = 1e16;
  11. const double EPS = 1e-7;
  12. const double PI = 3.1415926;
  13.  
  14. int main() {
  15. freopen("input.txt", "r", stdin);
  16. //freopen("output.txt", "w", stdout);
  17.  
  18. ios_base::sync_with_stdio(false);
  19. cin.tie(0), cout.tie(0);
  20.  
  21. string s;
  22. int k;
  23.  
  24. cin >> s >> k;
  25.  
  26. if (k > 0) {
  27. string sFixed = s;
  28.  
  29. for (int i = 0; i < k - 1; ++i) {
  30. if ((int)s.size() > 1023) {
  31. cout << s.substr(0, 1023);
  32.  
  33. return 0;
  34. }
  35.  
  36. int n = (int)s.size(), m = (int)sFixed.size();
  37.  
  38. if (n + m > 1023) {
  39. int ost = 1023 - n;
  40.  
  41. cout << s + sFixed.substr(0, ost);
  42.  
  43. return 0;
  44. }
  45. else {
  46. s += sFixed;
  47. }
  48. }
  49.  
  50. cout << s;
  51. }
  52. else {
  53. k = -k;
  54.  
  55. if ((int)s.size() % k != 0) {
  56. cout << "NO SOLUTION";
  57.  
  58. return 0;
  59. }
  60.  
  61. int f = (int)s.size() / k;
  62. string st = s.substr(0, f);
  63. string stt = st;
  64.  
  65. for (int i = 0; i < k - 1; ++i) {
  66. stt += st;
  67. }
  68.  
  69. if (stt == s) {
  70. cout << st;
  71. }
  72. else {
  73. cout << "NO SOLUTION";
  74. }
  75. }
  76.  
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement