Skip to content

Instantly share code, notes, and snippets.

@Park-Developer
Created April 16, 2022 06:59
Show Gist options
  • Save Park-Developer/ea3cd7fa1e42b2ebabe369b4b7c81fc6 to your computer and use it in GitHub Desktop.
Save Park-Developer/ea3cd7fa1e42b2ebabe369b4b7c81fc6 to your computer and use it in GitHub Desktop.
2진 변환(C++)
#include <iostream>
#include <queue>
#include <list>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
tuple<int, vector<int>> tenConvertTwo(int num){
vector<int> temp;
int result=0;
for(int i=1; num>0; i*=10){
int binary=num%2;
result+= binary*i;
temp.push_back(binary);
cout << "binary" << binary << ", ";
num/=2;
}
reverse(temp.begin(), temp.end());
cout << endl;
return make_tuple(result, temp);
}
int main(){
tuple<int, vector<int>> result;
result=tenConvertTwo(10);
cout << "Result " << endl;
cout << get<0>(result) << endl;
for(int v=0; v< get<1>(result).size(); v++){
cout << get<1>(result)[v] << " ";
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment