#include #include #include using namespace std; void proc(int n, string s) { int top; int i, j, index; /* Calculate the total number of strings. */ top = 1; for (i = 0; i < n; i++) top *= s.size(); /* Now, enumerate a separate index for each string. You will calculate the individual characters using div/mod, as explained in the enumeration lecture notes. */ for (index = 0; index < top; index++) { i = index; for (j = 0; j < n; j++) { printf("%c", s[i%s.size()]); i /= s.size(); } printf("\n"); } } int main(int argc, char **argv) { int n; string s; if (argc != 3) { fprintf(stderr, "usage: q4 n s\n"); exit(1); } n = atoi(argv[1]); s = argv[2]; proc(n, s); }