Ser1ousSAM

Untitled

Nov 16th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5. typedef long long ll;
  6.  
  7. int main() {
  8. int n;
  9. bool sign=0;
  10. cin >> n;
  11. if (n < 0) {
  12. sign = 1;
  13. n *= -1;
  14. }
  15. string temp_str, ans, t_s1;
  16. int t;
  17. while (n != 0) {
  18. t = (n - ((n / 3) * 3));
  19. t_s1 = to_string(t);
  20. temp_str.push_back(t_s1[0]);
  21. n /= 3;
  22. }
  23. int temp_n;
  24. string t_s2;
  25. temp_str.push_back('0');
  26. for (int i = 0; i < temp_str.size(); i++) {
  27. if (temp_str[i] == '2') {
  28. ans.push_back('$');
  29. temp_n = atoi(&temp_str[i+1]);
  30. temp_n++;
  31. t_s2 = to_string(temp_n);
  32. temp_str[i + 1]= t_s2[0];
  33. }
  34. else if (temp_str[i] == '3') {
  35. ans.push_back('0');
  36. temp_n = atoi(&temp_str[i + 1]);
  37. temp_n ++;
  38. t_s2 = to_string(temp_n);
  39. temp_str[i + 1] = t_s2[0];
  40. }
  41. else {
  42. ans.push_back(temp_str[i]);
  43. }
  44. }
  45. reverse(ans.begin(),ans.end());
  46. if (sign == 1) {
  47. for (int i = 0; i < ans.size(); i++) {
  48. if (ans[i] == '1') {
  49. ans[i] = '$';
  50. }
  51. else if (ans[i] == '$') {
  52. ans[i] = '1';
  53. }
  54. }
  55. }
  56.  
  57. for (int j = 0; j < ans.size(); j++) {
  58. cout << ans[j];
  59. }
  60. return 0;
  61. }
Add Comment
Please, Sign In to add comment