Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char** argv) {
- int count_of_numbers;
- scanf("%d", &count_of_numbers);
- unsigned long long numbers[count_of_numbers];
- int i;
- for (i = 0; i < count_of_numbers; i++) {
- scanf("%llu", &numbers[i]);
- }
- while (1) {
- char direction[6];
- scanf("%s", direction);
- if (strcmp(direction, "end") == 0) {
- break;
- }
- unsigned long long start_position;
- scanf("%llu", &start_position);
- unsigned long long mask = 1;
- int number_index;
- for (number_index = 0; number_index < count_of_numbers; number_index++) {
- int bit_index;
- int target_index;
- int target_set = 0;
- if (strcmp(direction, "right") == 0) {
- for (bit_index = 0; bit_index <= start_position; bit_index++) {
- unsigned long long bit = (numbers[number_index] >> bit_index) & mask;
- if (bit == 1 && target_set == 1) {
- numbers[number_index] |= mask << target_index;
- numbers[number_index] &= ~(mask << bit_index);
- target_set = 0;
- bit_index = 0;
- } else if (bit == 0 && target_set == 0) {
- target_index = bit_index;
- target_set = 1;
- }
- }
- } else if (strcmp(direction, "left") == 0) {
- for (bit_index = 63; bit_index >= start_position; bit_index--) {
- unsigned long long bit = (numbers[number_index] >> bit_index) & mask;
- if (bit == 1 && target_set == 1) {
- numbers[number_index] |= mask << target_index;
- numbers[number_index] &= ~(mask << bit_index);
- target_set = 0;
- bit_index = 63;
- } else if (bit == 0 && target_set == 0) {
- target_index = bit_index;
- target_set = 1;
- }
- }
- }
- }
- }
- for (i = 0; i < count_of_numbers; i++) {
- printf("%llu\n", numbers[i]);
- }
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment