gs.cpp 696 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Outputs a string of the given structure.
  3. *
  4. * gs <number of parts k> <part1_repeat_count> <part1_period> <part2_repeat_count> <part2_period> ... <partk_repeat_count> <partk_period>
  5. *
  6. * Examples:
  7. * gs 1 4 ab => abababab
  8. * gs 2 5 a 1 b => aaaaab
  9. * gs 3 1 a 5 b 1 a => abbbbba
  10. */
  11. #include "testlib.h"
  12. #include <string>
  13. using namespace std;
  14. int main(int argc, char *argv[]) {
  15. registerGen(argc, argv, 1);
  16. string t;
  17. int n = opt<int>(1);
  18. for (int i = 2; i <= 1 + 2 * n; i += 2) {
  19. int k = opt<int>(i);
  20. string s = opt<string>(i + 1);
  21. for (int j = 0; j < k; j++)
  22. t += s;
  23. }
  24. println(t);
  25. }