//
// Created by peter on 11/23/16.
//
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
void print2powstr(int n, string& out){
for(int i=0; i <n; i++){
out+="(1+1)*";
}
}
void printClosingBrackets(int n, string &out){
for(int i=0; i <n ; i++){
out +=")";
}
}
void printAnswer(int n){
if(n==1){
cout << "1\n";
return;
}
int binIndex = 1;
int toEx = 0;
int currentPow = 0;
int toClose = 0;
string out="";
while(currentPow < 30){
if((binIndex & n) != 0){
print2powstr(toEx, out);
out+= "(1+";
toEx=0;
toClose++;
}
currentPow++;
toEx++;
binIndex<<=1;
}
out.erase(out.begin() + out.size()-4, out.end());
printClosingBrackets(toClose-1, out);
cout <<out << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
int z;
cin >> z;
while(z--){
int n;
cin >> n;
printAnswer(n);
}
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 | // // Created by peter on 11/23/16. // #include <iostream> #include <algorithm> #include <string> using namespace std; void print2powstr(int n, string& out){ for(int i=0; i <n; i++){ out+="(1+1)*"; } } void printClosingBrackets(int n, string &out){ for(int i=0; i <n ; i++){ out +=")"; } } void printAnswer(int n){ if(n==1){ cout << "1\n"; return; } int binIndex = 1; int toEx = 0; int currentPow = 0; int toClose = 0; string out=""; while(currentPow < 30){ if((binIndex & n) != 0){ print2powstr(toEx, out); out+= "(1+"; toEx=0; toClose++; } currentPow++; toEx++; binIndex<<=1; } out.erase(out.begin() + out.size()-4, out.end()); printClosingBrackets(toClose-1, out); cout <<out << "\n"; } int main(){ ios_base::sync_with_stdio(false); int z; cin >> z; while(z--){ int n; cin >> n; printAnswer(n); } return 0; } |
English