This repository has been archived on 2026-07-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cmc/3sem/cnts/contest5/02.c
T
2025-04-13 21:48:15 +03:00

33 lines
550 B
C
Executable File

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
enum
{
MAX_MODE = 0777,
};
int
main(int argc, char *argv[])
{
const char s[] = "rwxrwxrwx";
for (int i = 1; i < argc; ++i) {
char *p;
errno = 0;
int n = strtol(argv[i], &p, 8);
if (errno || *p || p == argv[i] || n > MAX_MODE || n < 0) {
return 1;
}
for (int j = 0; j < sizeof(s) - 1; ++j) {
putchar((n & (1 << (sizeof(s) - 2 - j))) ? s[j] : '-');
}
printf("\n");
}
return 0;
}