fork download
  1. #include <stdio.h>
  2.  
  3. void input(int *buffer, int *length, int *c);
  4. void output(int *buffer, int length);
  5. void cyclic_shift(int *buffer, int length, int c);
  6.  
  7. int main() {
  8. int length;
  9. int buffer[10];
  10. int c;
  11. input(buffer, &length, &c);
  12. if (length < 1 || length > 10) {
  13. printf("n/a\n");
  14. return 1;
  15. }
  16. cyclic_shift(buffer, length, c);
  17. output(buffer, length);
  18. return 0;
  19. }
  20. void input(int *buffer, int *length, int *c) {
  21. scanf("%d", length);
  22. for (int i = 0; i < *length; i++) {
  23. scanf("%d", &buffer[i]);
  24. }
  25. scanf("%d", c);
  26. }
  27. void cyclic_shift(int *buffer, int length, int c) {
  28. if (length <= 0) return;
  29. c = c % length;
  30. if (c < 0) {
  31. c = length + c;
  32. }
  33. int temp[10];
  34. for (int i = 0; i < length; i++) {
  35. temp[i] = buffer[(i + c) % length];
  36. }
  37. for (int i = 0; i < length; i++) {
  38. buffer[i] = temp[i];
  39. }
  40. }
  41. void output(int *buffer, int length) {
  42. for (int i = 0; i < length; i++) {
  43. printf("%d ", buffer[i]);
  44. }
  45. printf("\n");
  46. }
Success #stdin #stdout 0s 5292KB
stdin
10
4 3 9 0 1 2 0 2 7 -1
2
stdout
9 0 1 2 0 2 7 -1 4 3