The_Law

Untitled

Oct 2nd, 2018
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. enum
  4. {
  5.     SMALL_START = 11,
  6.     BIG_START = 37,
  7.     THIRD_BIT = 3,
  8.     SECOND_BIT = 2,
  9.     MAX_CODE = 63
  10. };
  11.  
  12. int
  13. main(void)
  14. {
  15.     int curr = getchar();
  16.  
  17.     while (curr != EOF) {
  18.         _Bool skip = 0;
  19.  
  20.         if ('0' <= curr && curr <= '9') {
  21.             curr -= '0' - 1;
  22.         } else if ('a' <= curr && curr <= 'z') {
  23.             curr -= 'a' - SMALL_START;
  24.         } else if ('A' <= curr && curr <= 'Z') {
  25.             curr -= 'A' - BIG_START;
  26.         } else {
  27.             skip = 1;
  28.         }
  29.  
  30.         if (!skip) {
  31.             curr &= ~(1 << SECOND_BIT);
  32.             curr ^= (1 << THIRD_BIT);
  33.  
  34.             if (curr == 0) {
  35.                 putchar('@');
  36.             } else if (curr == MAX_CODE) {
  37.                 putchar('#');
  38.             } else if (BIG_START <= curr) {
  39.                 putchar(curr - BIG_START + 'A');
  40.             } else if (SMALL_START <= curr) {
  41.                 putchar(curr - SMALL_START + 'a');
  42.             } else {
  43.                 putchar(curr - 1 + '0');
  44.             }
  45.         }
  46.         curr = getchar();
  47.     }
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment