#include <iostream> #include <string> using namespace std; string Create(int n){ string res; if(n==1) return "1"; if(n==0) return ""; if(n%2 == 1) res = "(1+(1+1)*"; else res = "(1+1)*"; res += Create(n/2); if(n%2) res += ")"; return res; } int main(){ ios_base::sync_with_stdio(0); int n,i,t; string s; cin >> t; for(i=0; i<t; i++){ cin >> n; s = Create(n); cout << s << "\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 | #include <iostream> #include <string> using namespace std; string Create(int n){ string res; if(n==1) return "1"; if(n==0) return ""; if(n%2 == 1) res = "(1+(1+1)*"; else res = "(1+1)*"; res += Create(n/2); if(n%2) res += ")"; return res; } int main(){ ios_base::sync_with_stdio(0); int n,i,t; string s; cin >> t; for(i=0; i<t; i++){ cin >> n; s = Create(n); cout << s << "\n"; } return 0; } |