#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int result = 0;
string print(int p) {
string s = "";
int n = p >> 1;
if (p & 1) {
s += "1";
result++;
if (n)
s += "+";
}
if (n) {
s += "(1+1)";
result += 2;
if (n & ~1) {
s += "*";
if (n & 1)
s += "(";
s += print(n);
if (n & 1)
s += ")";
}
}
if (result > 100)
return "NIE";
return s;
}
void solve() {
int k, s = 0;
cin >> k;
result = 0;
cout << print(k);
//while (open--) cout << ")";
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while ( t-- ) {
solve();
}
}
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 | #include <iostream> #include <cstdlib> #include <string> using namespace std; int result = 0; string print(int p) { string s = ""; int n = p >> 1; if (p & 1) { s += "1"; result++; if (n) s += "+"; } if (n) { s += "(1+1)"; result += 2; if (n & ~1) { s += "*"; if (n & 1) s += "("; s += print(n); if (n & 1) s += ")"; } } if (result > 100) return "NIE"; return s; } void solve() { int k, s = 0; cin >> k; result = 0; cout << print(k); //while (open--) cout << ")"; cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while ( t-- ) { solve(); } } |
English