#include<iostream> #include<cstring> using namespace std; string solve(int number) { string result(""); int output = number/2; if(output == 0) { return result; } string mid_part(solve(output)); if(number % 2 == 0) { if(mid_part != "") result += "(1+1)*" + mid_part; else result += "(1+1)"; } else { if(mid_part != "") result += "((1+1)*" + mid_part + "+1)"; else result += "(1+1+1)"; } return result; } int main() { int t; cin>>t; int * k; k = new int[t]; for(int i = 0; i < t; i++) cin>>k[i]; for(int i = 0; i < t; i++) { string result; if(k[i] != 1) result = solve(k[i]); else result = "1"; cout<<result<<endl; } }
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 | #include<iostream> #include<cstring> using namespace std; string solve(int number) { string result(""); int output = number/2; if(output == 0) { return result; } string mid_part(solve(output)); if(number % 2 == 0) { if(mid_part != "") result += "(1+1)*" + mid_part; else result += "(1+1)"; } else { if(mid_part != "") result += "((1+1)*" + mid_part + "+1)"; else result += "(1+1+1)"; } return result; } int main() { int t; cin>>t; int * k; k = new int[t]; for(int i = 0; i < t; i++) cin>>k[i]; for(int i = 0; i < t; i++) { string result; if(k[i] != 1) result = solve(k[i]); else result = "1"; cout<<result<<endl; } } |