Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //It DOES NOT convert to the proper base3 number,
- //it converts it to the reverse base3 number, such as:
- //2077 = 2211221 (Correct)
- //2077 = 1221122 (Reversed version)
- int base_3(int n) {
- int z = n%3 + 1;
- int aux = z;
- n = n/3;
- while (n != 0) {
- z = n%3 + 1;
- aux = 10*aux + z;
- n = n/3;
- }
- return aux;
- }
- int main() {
- int n;
- while (cin >> n) {
- if (n < 0) { //Add ":" at the beginning if its negative.
- n = -1*n;
- cout << ':';
- }
- n = base_3(n); //Convert "n" to base 3
- while (n != 0) {
- if (n%10 == 1) cout << "-"; //Prints the correct symbol
- else if (n%10 == 2) cout << "+"; //for each value
- else if (n%10 == 3) cout << "*";
- n = n/10;
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement