#include <iostream> #include <vector> using namespace std; string getMoveMultiplier(int n, string moves) { string orgMoves = moves; string out = ""; if (n == 1) return moves; if (n <= 9) { if (orgMoves.size() > 1) { out = "["; } out = out+orgMoves; //((char)(n + '0')) + "[" + if (orgMoves.size() > 1) { out = out + "]"; } out = ((char)(n + '0')) + out; return out; } vector<pair<int, int>> tmp; int i = 0; int divisor = 9; while (n) { if (n % divisor) tmp.push_back({ i, n % divisor }); n /= divisor; i++; } out = ""; for (int i = 0; i < tmp.size(); i++) { for (int j = 0; j < tmp[i].first; j++) { out = out + ((char)(divisor+'0')); if (orgMoves.size() * tmp[i].second == 1 && j == tmp[i].first - 1) continue; out = out + "["; } for(int j = 0; j<tmp[i].second; j++) out = out + orgMoves; for (int j = 0; j < tmp[i].first; j++) { if (orgMoves.size() * tmp[i].second == 1 && j == tmp[i].first - 1) continue; out += "]"; } } return out; } int main() { int n; cin >> n; //string tmp; for (int i = n; i > 0; i--) { //cout<<i<<"C"; cout << getMoveMultiplier(i, "C"); //tmp += getMoveMultiplier(i, "C"); if (i > 1) { cout << getMoveMultiplier(i - 1, "AE"); //tmp+= getMoveMultiplier(i - 1, "AE"); } //cout<<i-1<<"[AE]"; //tmp += "A"; cout << "A"; } //tmp += getMoveMultiplier(n, "E"); cout << getMoveMultiplier(n, "E"); //cout<<n<<"E"; //cout << endl<<tmp.size(); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #include <iostream> #include <vector> using namespace std; string getMoveMultiplier(int n, string moves) { string orgMoves = moves; string out = ""; if (n == 1) return moves; if (n <= 9) { if (orgMoves.size() > 1) { out = "["; } out = out+orgMoves; //((char)(n + '0')) + "[" + if (orgMoves.size() > 1) { out = out + "]"; } out = ((char)(n + '0')) + out; return out; } vector<pair<int, int>> tmp; int i = 0; int divisor = 9; while (n) { if (n % divisor) tmp.push_back({ i, n % divisor }); n /= divisor; i++; } out = ""; for (int i = 0; i < tmp.size(); i++) { for (int j = 0; j < tmp[i].first; j++) { out = out + ((char)(divisor+'0')); if (orgMoves.size() * tmp[i].second == 1 && j == tmp[i].first - 1) continue; out = out + "["; } for(int j = 0; j<tmp[i].second; j++) out = out + orgMoves; for (int j = 0; j < tmp[i].first; j++) { if (orgMoves.size() * tmp[i].second == 1 && j == tmp[i].first - 1) continue; out += "]"; } } return out; } int main() { int n; cin >> n; //string tmp; for (int i = n; i > 0; i--) { //cout<<i<<"C"; cout << getMoveMultiplier(i, "C"); //tmp += getMoveMultiplier(i, "C"); if (i > 1) { cout << getMoveMultiplier(i - 1, "AE"); //tmp+= getMoveMultiplier(i - 1, "AE"); } //cout<<i-1<<"[AE]"; //tmp += "A"; cout << "A"; } //tmp += getMoveMultiplier(n, "E"); cout << getMoveMultiplier(n, "E"); //cout<<n<<"E"; //cout << endl<<tmp.size(); return 0; } |