Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void input(int *buffer, int *length, int *shift);
- void output(int *buffer, int length);
- void make_shift(int *buffer, int length, int shift);
- int main() {
- int buffer[10], length, shift;
- input(buffer, &length, &shift);
- if (length != 0) {
- make_shift(buffer, length, shift);
- output(buffer, length);
- } else
- printf("n/a");
- return 0;
- }
- void input(int *buffer, int *length, int *shift) {
- int status = 0;
- char c = ' ';
- if (scanf("%d%c", length, &c) == 2 && c != '.' && *length > 0 && *length <= 10) {
- for (int p = 0; p < *length && status == 0; p++) {
- if (scanf("%d%c", buffer + p, &c) != 2 || c == '.') {
- status = 1;
- }
- }
- } else
- status = 1;
- status = scanf("%d%c", shift, &c) == 2 && c != '.' ? status : 1;
- *length = status == 1 ? 0 : *length;
- }
- void output(int *buffer, int length) {
- for (int i = 0; i < length; ++i) {
- printf("%d ", *(buffer++));
- }
- printf("\b");
- }
- void make_shift(int *buffer, int length, int shift) {
- shift %= length;
- if (shift < 0) {
- shift *= -1;
- shift = length - shift;
- }
- int hash[10];
- for (int i = 0; i < shift; ++i) {
- hash[i] = buffer[i];
- }
- for (int i = shift; i < length; ++i) {
- buffer[i - shift] = buffer[i];
- }
- int j = 0;
- for (int i = length - shift; i < length; ++i) {
- buffer[i] = hash[j++];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement