SHARE
TWEET

Untitled

a guest Sep 13th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <unistd.h>
  2. #include <sys/mman.h>
  3. #include <sys/stat.h>
  4. #include <sys/types.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. char *tab;
  9.  
  10. int ft_weird_atoi(void)
  11. {
  12.     int ret= 0, sign = 1;
  13.     if (*tab == '-')
  14.     {
  15.         sign = -1;
  16.         ++tab;
  17.     }
  18.     while (*tab != '\n')
  19.         ret = ret * 10 + *tab++ - '0';
  20.     ++tab;
  21.     return ret * sign;
  22. }
  23.  
  24. int main()
  25. {
  26.     struct stat s_stat;
  27.     fstat(0, &s_stat);
  28.  
  29.     tab = (char *)mmap(0, s_stat.st_size, PROT_READ, MAP_SHARED, STDIN_FILENO, 0);
  30.     int summ = 0;
  31.     char *fin = tab + s_stat.st_size;
  32.     ft_weird_atoi();
  33.     while (tab != fin)
  34.         summ += ft_weird_atoi();
  35.     printf("%d\n", summ);
  36. }
RAW Paste Data
Top