Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- const int INF = 1e9;
- const ll bINF = 1e16;
- const double EPS = 1e-7;
- const double PI = 3.1415926;
- int main() {
- freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(0), cout.tie(0);
- string s;
- int k;
- cin >> s >> k;
- if (k > 0) {
- string sFixed = s;
- for (int i = 0; i < k - 1; ++i) {
- if ((int)s.size() > 1023) {
- cout << s.substr(0, 1023);
- return 0;
- }
- int n = (int)s.size(), m = (int)sFixed.size();
- if (n + m > 1023) {
- int ost = 1023 - n;
- cout << s + sFixed.substr(0, ost);
- return 0;
- }
- else {
- s += sFixed;
- }
- }
- cout << s;
- }
- else {
- k = -k;
- if ((int)s.size() % k != 0) {
- cout << "NO SOLUTION";
- return 0;
- }
- int f = (int)s.size() / k;
- string st = s.substr(0, f);
- string stt = st;
- for (int i = 0; i < k - 1; ++i) {
- stt += st;
- }
- if (stt == s) {
- cout << st;
- }
- else {
- cout << "NO SOLUTION";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement