Guest User

Untitled

a guest
Dec 11th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #ifdef __cplusplus
  2.  
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <string>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <set>
  11. #include <map>
  12. #include <cmath>
  13.  
  14. // forprak
  15.  
  16. #include <unistd.h>
  17. #include <fcntl.h>
  18. #include <climits>
  19. #include <elf.h>
  20. #include <sys/stat.h>
  21. #include <dirent.h>
  22.  
  23. // endforprak
  24.  
  25. using namespace std;
  26.  
  27. #else
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <math.h>
  33. #include <unistd.h>
  34. #include <fcntl.h>
  35. #include <limits.h>
  36. #include <elf.h>
  37. #include <stdbool.h>
  38. #include <time.h>
  39. #include <sys/stat.h>
  40. #include <dirent.h>
  41.  
  42. #endif
  43.  
  44. typedef long long ll;
  45. typedef struct tm tm;
  46.  
  47. #define sqrt(x) (sqrt(abs((x))))
  48. #define mp make_pair
  49. #define pb push_back
  50. #define sqr(o) ((o)*(o))
  51.  
  52. int main(int argc, char ** argv)
  53. {
  54.     //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
  55.     //freopen("highways.in", "r", stdin);freopen("highways.out", "w", stdout);
  56.  
  57.     DIR * d;
  58.     if (!(d = opendir(argv[1])))
  59.     {
  60.         return 0;
  61.     }
  62.  
  63.     char path[PATH_MAX] = {0};
  64.     strcpy(path, argv[1]);
  65.     int l = strlen(path);
  66.     path[l++] = '/';
  67.     char * ppath = path + l;
  68.  
  69.  
  70.     ll ans = 0;
  71.     struct dirent *file;
  72.     while ((file = readdir(d)))
  73.     {
  74.         struct stat s;
  75.         strcpy(ppath, file->d_name);
  76.         stat(path, &s);
  77.         if (S_ISREG(s.st_mode) && !(S_ISLNK(s.st_mode)))
  78.         {
  79.             //printf("%s --> %d\n", path, s.st_size);
  80.             ans += s.st_size;
  81.         }
  82.     }
  83.  
  84.     printf("%lld\n", ans);
  85.  
  86.     closedir(d);
  87.  
  88.     return 0;
  89. }
Add Comment
Please, Sign In to add comment