#include <cstdio> char buffer[100 * 100]; // Should be big enough inline void putString(char* &bufp, const char * sz) { while (*sz) *bufp++ = *sz++; } void testCase() { int n; int parCount = 0; char * bufp = buffer; scanf("%d", &n); while (n > 0) { if (n <= 3) { *bufp++ = '1'; while (--n > 0) { *bufp++ = '+'; *bufp++ = '1'; } } else { if (n & 1) { putString(bufp, "1+"); } putString(bufp, "(1+1)*("); parCount++; n >>= 1; } } while (parCount --> 0) *bufp++ = ')'; *bufp = '\0'; puts(buffer); } int main() { int t; scanf("%d", &t); while (t --> 0) testCase(); 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 | #include <cstdio> char buffer[100 * 100]; // Should be big enough inline void putString(char* &bufp, const char * sz) { while (*sz) *bufp++ = *sz++; } void testCase() { int n; int parCount = 0; char * bufp = buffer; scanf("%d", &n); while (n > 0) { if (n <= 3) { *bufp++ = '1'; while (--n > 0) { *bufp++ = '+'; *bufp++ = '1'; } } else { if (n & 1) { putString(bufp, "1+"); } putString(bufp, "(1+1)*("); parCount++; n >>= 1; } } while (parCount --> 0) *bufp++ = ')'; *bufp = '\0'; puts(buffer); } int main() { int t; scanf("%d", &t); while (t --> 0) testCase(); return 0; } |