Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- typedef long long ll;
- int main() {
- int n;
- bool sign=0;
- cin >> n;
- if (n < 0) {
- sign = 1;
- n *= -1;
- }
- string temp_str, ans, t_s1;
- int t;
- while (n != 0) {
- t = (n - ((n / 3) * 3));
- t_s1 = to_string(t);
- temp_str.push_back(t_s1[0]);
- n /= 3;
- }
- int temp_n;
- string t_s2;
- temp_str.push_back('0');
- for (int i = 0; i < temp_str.size(); i++) {
- if (temp_str[i] == '2') {
- ans.push_back('$');
- temp_n = atoi(&temp_str[i+1]);
- temp_n++;
- t_s2 = to_string(temp_n);
- temp_str[i + 1]= t_s2[0];
- }
- else if (temp_str[i] == '3') {
- ans.push_back('0');
- temp_n = atoi(&temp_str[i + 1]);
- temp_n ++;
- t_s2 = to_string(temp_n);
- temp_str[i + 1] = t_s2[0];
- }
- else {
- ans.push_back(temp_str[i]);
- }
- }
- reverse(ans.begin(),ans.end());
- if (sign == 1) {
- for (int i = 0; i < ans.size(); i++) {
- if (ans[i] == '1') {
- ans[i] = '$';
- }
- else if (ans[i] == '$') {
- ans[i] = '1';
- }
- }
- }
- for (int j = 0; j < ans.size(); j++) {
- cout << ans[j];
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment