#include <stdio.h> #include <string.h> #include <stdlib.h> int main(){ unsigned int n; unsigned int t; char *cards; scanf("%u %u\n", &n, &t); size_t cards_amount = 2<<n; cards = (char *)malloc(cards_amount * sizeof(char)); unsigned int end = getline(&cards, &cards_amount, stdin); if(cards[end - 1] == '\n'){ cards[end - 1] = '\0'; end--; } unsigned int start = end - 1; if(t % 2 == 0){ puts(cards); } else{ while(1){ while(cards[start] != ' ' && start != 0){ start--; } if(start == 0){ printf("%.*s", end, cards); break; } printf("%.*s ", end-start-1, cards+start+1); end = start; start--; } } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <stdio.h> #include <string.h> #include <stdlib.h> int main(){ unsigned int n; unsigned int t; char *cards; scanf("%u %u\n", &n, &t); size_t cards_amount = 2<<n; cards = (char *)malloc(cards_amount * sizeof(char)); unsigned int end = getline(&cards, &cards_amount, stdin); if(cards[end - 1] == '\n'){ cards[end - 1] = '\0'; end--; } unsigned int start = end - 1; if(t % 2 == 0){ puts(cards); } else{ while(1){ while(cards[start] != ' ' && start != 0){ start--; } if(start == 0){ printf("%.*s", end, cards); break; } printf("%.*s ", end-start-1, cards+start+1); end = start; start--; } } return 0; } |