Advertisement
Korobka887

T06D09

Mar 8th, 2023
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void input(int *buffer, int *length, int *shift);
  4. void output(int *buffer, int length);
  5. void make_shift(int *buffer, int length, int shift);
  6.  
  7. int main() {
  8.     int buffer[10], length, shift;
  9.  
  10.     input(buffer, &length, &shift);
  11.  
  12.     if (length != 0) {
  13.         make_shift(buffer, length, shift);
  14.         output(buffer, length);
  15.     } else
  16.         printf("n/a");
  17.     return 0;
  18. }
  19.  
  20. void input(int *buffer, int *length, int *shift) {
  21.     int status = 0;
  22.     char c = ' ';
  23.     if (scanf("%d%c", length, &c) == 2 && c != '.' && *length > 0 && *length <= 10) {
  24.         for (int p = 0; p < *length && status == 0; p++) {
  25.             if (scanf("%d%c", buffer + p, &c) != 2 || c == '.') {
  26.                 status = 1;
  27.             }
  28.         }
  29.     } else
  30.         status = 1;
  31.  
  32.     status = scanf("%d%c", shift, &c) == 2 && c != '.' ? status : 1;
  33.  
  34.     *length = status == 1 ? 0 : *length;
  35. }
  36.  
  37. void output(int *buffer, int length) {
  38.     for (int i = 0; i < length; ++i) {
  39.         printf("%d ", *(buffer++));
  40.     }
  41.     printf("\b");
  42. }
  43.  
  44. void make_shift(int *buffer, int length, int shift) {
  45.     shift %= length;
  46.  
  47.     if (shift < 0) {
  48.         shift *= -1;
  49.         shift = length - shift;
  50.     }
  51.  
  52.     int hash[10];
  53.     for (int i = 0; i < shift; ++i) {
  54.         hash[i] = buffer[i];
  55.     }
  56.  
  57.     for (int i = shift; i < length; ++i) {
  58.         buffer[i - shift] = buffer[i];
  59.     }
  60.  
  61.     int j = 0;
  62.     for (int i = length - shift; i < length; ++i) {
  63.         buffer[i] = hash[j++];
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement