Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/mman.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- void
- func(char *n_str, int *buff, int i)
- {
- long long n;
- int res = 0;
- sscanf(n_str, "%lld", &n);
- while (n) {
- res += n % 4 > 0 ? n % 4 : - (n % 4);
- n /= 4;
- }
- buff[i] = res;
- }
- int
- main(int argc, char *argv[])
- {
- int *buff = mmap(NULL, sizeof(int) * (argc - 1), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- for (int i = 1; i < argc; ++i) {
- if (!fork()) {
- func(argv[i], buff, i - 1);
- _exit(0);
- }
- }
- for (int i = 1; i < argc; ++i) {
- wait(NULL);
- }
- for (int i = 0; i < argc - 1; ++i) {
- printf("%d\n", buff[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement