init commit
This commit is contained in:
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <linux/limits.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char const_str[] = "18446744073709551616";
|
||||
|
||||
char tmp_str[PATH_MAX];
|
||||
|
||||
while (scanf("%s", tmp_str) == 1) {
|
||||
int64_t res = 0;
|
||||
uint64_t base = 1;
|
||||
|
||||
int is_overflow = 0;
|
||||
|
||||
for (int i = strlen(tmp_str) - 1; i >= 0; i--) {
|
||||
char ch = tmp_str[i];
|
||||
|
||||
if (ch == 'a') {
|
||||
if (__builtin_sub_overflow(res, base, &res)) {
|
||||
is_overflow = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (ch == '1') {
|
||||
if (__builtin_add_overflow(res, base, &res)) {
|
||||
is_overflow = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (ch != '0') {
|
||||
fprintf(stderr, "Invalid input\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (__builtin_mul_overflow(base, 3, &base) && i != 0) {
|
||||
is_overflow = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_overflow) {
|
||||
printf("%s\n", const_str);
|
||||
} else {
|
||||
printf("%lld\n", res);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+98
@@ -0,0 +1,98 @@
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_SYM_THREE_LEN = 64,
|
||||
SYS_BASE = 3,
|
||||
};
|
||||
|
||||
const char ERROR_OUTPUT[] = "18446744073709551616";
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int cur_num = getchar();
|
||||
while (cur_num != EOF && isspace(cur_num)) {
|
||||
cur_num = getchar();
|
||||
}
|
||||
long long res = 0;
|
||||
bool overflow = false;
|
||||
bool printed = false;
|
||||
bool read = false;
|
||||
while (cur_num != EOF) {
|
||||
char cur_ch = cur_num;
|
||||
if (isspace(cur_num)) {
|
||||
if (!printed) {
|
||||
if (overflow) {
|
||||
printf("%s\n", ERROR_OUTPUT);
|
||||
} else {
|
||||
printf("%lld\n", res);
|
||||
}
|
||||
res = 0;
|
||||
overflow = false;
|
||||
printed = true;
|
||||
}
|
||||
} else {
|
||||
read = true;
|
||||
printed = false;
|
||||
if (cur_ch == '1') {
|
||||
long long temp = 0;
|
||||
if (res < 0) {
|
||||
if (__builtin_mul_overflow(res + 1, 3, &temp)) {
|
||||
overflow = true;
|
||||
}
|
||||
if (__builtin_add_overflow(temp, 1, &res)) {
|
||||
overflow = true;
|
||||
}
|
||||
if (__builtin_sub_overflow(res, 3, &temp)) {
|
||||
overflow = true;
|
||||
}
|
||||
res = temp;
|
||||
} else {
|
||||
if (__builtin_mul_overflow(res, 3, &temp)) {
|
||||
overflow = true;
|
||||
}
|
||||
if (__builtin_add_overflow(temp, 1, &res)) {
|
||||
overflow = true;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (cur_ch == 'a') {
|
||||
long long temp = 0;
|
||||
if (res > 0) {
|
||||
if (__builtin_mul_overflow(res - 1, 3, &temp)) {
|
||||
overflow = true;
|
||||
}
|
||||
if (__builtin_sub_overflow(temp, 1, &res)) {
|
||||
overflow = true;
|
||||
}
|
||||
if (__builtin_add_overflow(res, 3, &temp)) {
|
||||
overflow = true;
|
||||
}
|
||||
res = temp;
|
||||
} else {
|
||||
if (__builtin_mul_overflow(res, 3, &temp)) {
|
||||
overflow = true;
|
||||
}
|
||||
if (__builtin_sub_overflow(temp, 1, &res)) {
|
||||
overflow = true;
|
||||
}
|
||||
}
|
||||
} else if (cur_ch == '0') {
|
||||
long long temp = 0;
|
||||
if (__builtin_mul_overflow(res, 3, &temp)) {
|
||||
overflow = true;
|
||||
}
|
||||
res = temp;
|
||||
}
|
||||
}
|
||||
cur_num = getchar();
|
||||
}
|
||||
if (cur_num == EOF && !printed && !overflow && read) {
|
||||
printf("%lld\n", res);
|
||||
}
|
||||
}
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <linux/limits.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char const_str[] = "18446744073709551616";
|
||||
int ch, index = 0;
|
||||
int64_t res = 0;
|
||||
int is_overflow = 0;
|
||||
|
||||
while ((ch = getchar()) != EOF) {
|
||||
if (!isspace(ch)) {
|
||||
index = 1;
|
||||
int64_t tmp = 0;
|
||||
if (ch == 'a') {
|
||||
if (res > 0) {
|
||||
if (__builtin_mul_overflow(res - 1, 3, &tmp)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
if (__builtin_sub_overflow(tmp, 1, &res)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
if (__builtin_add_overflow(res, 3, &tmp)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
res = tmp;
|
||||
} else {
|
||||
if (__builtin_mul_overflow(res, 3, &tmp)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
if (__builtin_sub_overflow(tmp, 1, &res)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (ch == '1') {
|
||||
if (res > 0) {
|
||||
if (__builtin_mul_overflow(res, 3, &tmp)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
if (__builtin_add_overflow(tmp, 1, &res)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
} else {
|
||||
if (__builtin_mul_overflow(res + 1, 3, &tmp)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
if (__builtin_add_overflow(tmp, 1, &res)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
if (__builtin_sub_overflow(res, 3, &tmp)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
res = tmp;
|
||||
}
|
||||
} else if (ch == '0') {
|
||||
if (__builtin_mul_overflow(res, 3, &res)) {
|
||||
is_overflow = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (index) {
|
||||
if (is_overflow) {
|
||||
printf("%s\n", const_str);
|
||||
} else {
|
||||
printf("%lld\n", res);
|
||||
}
|
||||
|
||||
index = 0;
|
||||
res = 0;
|
||||
is_overflow = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (index) {
|
||||
if (is_overflow) {
|
||||
printf("%s\n", const_str);
|
||||
} else {
|
||||
printf("%lld\n", res);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
enum
|
||||
{
|
||||
THURSDAY = 4,
|
||||
YEAR_OFFSET = 1900,
|
||||
LAST_DIGIT_REM = 3,
|
||||
GOOD_THURSDAY1 = 2,
|
||||
GOOD_THURSDAY2 = 4
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int year;
|
||||
if (scanf("%d", &year) != 1) {
|
||||
fprintf(stderr, "Invalid input\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct tm t = {0};
|
||||
t.tm_isdst = -1;
|
||||
t.tm_mday = 1;
|
||||
t.tm_year = year - YEAR_OFFSET;
|
||||
|
||||
int num_of_thursdays = 0, last_month = 0;
|
||||
|
||||
while (t.tm_year == year - YEAR_OFFSET) {
|
||||
mktime(&t);
|
||||
|
||||
if (t.tm_mon != last_month) {
|
||||
last_month = t.tm_mon;
|
||||
num_of_thursdays = 0;
|
||||
}
|
||||
|
||||
if (t.tm_wday == THURSDAY) {
|
||||
num_of_thursdays++;
|
||||
|
||||
if (t.tm_mday % LAST_DIGIT_REM != 0 &&
|
||||
(num_of_thursdays == GOOD_THURSDAY1 || num_of_thursdays == GOOD_THURSDAY2)) {
|
||||
printf("%d %d\n", t.tm_mon + 1, t.tm_mday);
|
||||
}
|
||||
|
||||
t.tm_mday += 7;
|
||||
} else {
|
||||
t.tm_mday++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
void
|
||||
check_and_sum_files(const char *dir1, const char *dir2, off_t *total_size)
|
||||
{
|
||||
DIR *d1 = opendir(dir1);
|
||||
if (!d1) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(d1)) != NULL) {
|
||||
char path1[PATH_MAX];
|
||||
int r = snprintf(path1, sizeof(path1), "%s/%s", dir1, entry->d_name);
|
||||
if (r < 0 || r >= sizeof(path1)) {
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
struct stat st1;
|
||||
if (lstat(path1, &st1) == -1 || !S_ISREG(st1.st_mode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (access(path1, W_OK) == 0) {
|
||||
char path2[PATH_MAX];
|
||||
r = snprintf(path2, sizeof(path2), "%s/%s", dir2, entry->d_name);
|
||||
if (r < 0 || r >= sizeof(path2)) {
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
struct stat st2;
|
||||
if (stat(path2, &st2) == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (S_ISREG(st2.st_mode) && st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
|
||||
*total_size += st1.st_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(d1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: %s <directory1> <directory2>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
off_t total_size = 0;
|
||||
check_and_sum_files(argv[1], argv[2], &total_size);
|
||||
|
||||
printf("%ld\n", total_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
Executable
+104
@@ -0,0 +1,104 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
enum
|
||||
{
|
||||
SYNODIC_PERIOD_DAYS = 29,
|
||||
SYNODIC_PERIOD_HOURS = 12,
|
||||
SYNODIC_PERIOD_MINUTES = 44,
|
||||
FULL_MOON_YEAR = 2021,
|
||||
FULL_MOON_MONTH = 5,
|
||||
FULL_MOON_DAY = 26,
|
||||
FULL_MOON_HOUR = 11,
|
||||
FULL_MOON_MINUTE = 14,
|
||||
};
|
||||
|
||||
void
|
||||
add_synodic_period(struct tm *tm)
|
||||
{
|
||||
tm->tm_mday += SYNODIC_PERIOD_DAYS;
|
||||
tm->tm_hour += SYNODIC_PERIOD_HOURS;
|
||||
tm->tm_min += SYNODIC_PERIOD_MINUTES;
|
||||
timegm(tm);
|
||||
}
|
||||
|
||||
void
|
||||
sub_synodic_period(struct tm *tm)
|
||||
{
|
||||
tm->tm_mday -= SYNODIC_PERIOD_DAYS;
|
||||
tm->tm_hour -= SYNODIC_PERIOD_HOURS;
|
||||
tm->tm_min -= SYNODIC_PERIOD_MINUTES;
|
||||
timegm(tm);
|
||||
}
|
||||
|
||||
struct tm
|
||||
find_full_moon_after(struct tm start)
|
||||
{
|
||||
struct tm full_moon = {0};
|
||||
full_moon.tm_isdst = -1;
|
||||
full_moon.tm_year = FULL_MOON_YEAR - 1900;
|
||||
full_moon.tm_mon = FULL_MOON_MONTH - 1;
|
||||
full_moon.tm_mday = FULL_MOON_DAY;
|
||||
full_moon.tm_hour = FULL_MOON_HOUR;
|
||||
full_moon.tm_min = FULL_MOON_MINUTE;
|
||||
timegm(&full_moon);
|
||||
|
||||
while (timegm(&full_moon) < timegm(&start)) {
|
||||
add_synodic_period(&full_moon);
|
||||
}
|
||||
|
||||
while (timegm(&full_moon) > timegm(&start)) {
|
||||
sub_synodic_period(&full_moon);
|
||||
}
|
||||
|
||||
add_synodic_period(&full_moon);
|
||||
|
||||
return full_moon;
|
||||
}
|
||||
|
||||
struct tm
|
||||
find_fourth_monday_after(struct tm start)
|
||||
{
|
||||
struct tm date = start;
|
||||
date.tm_mday++;
|
||||
|
||||
int num_of_mondays = 0;
|
||||
while (num_of_mondays < 4) {
|
||||
timegm(&date);
|
||||
|
||||
if (date.tm_wday == 1) {
|
||||
num_of_mondays++;
|
||||
}
|
||||
|
||||
date.tm_mday++;
|
||||
}
|
||||
|
||||
date.tm_mday--;
|
||||
|
||||
timegm(&date);
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int year;
|
||||
if (scanf("%d", &year) != 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct tm start = {0};
|
||||
start.tm_isdst = -1;
|
||||
start.tm_year = year - 1900;
|
||||
start.tm_mday = 257;
|
||||
|
||||
timegm(&start);
|
||||
|
||||
struct tm full_moon = find_full_moon_after(start);
|
||||
struct tm event_date = find_fourth_monday_after(full_moon);
|
||||
|
||||
printf("%04d-%02d-%02d\n", event_date.tm_year + 1900, event_date.tm_mon + 1, event_date.tm_mday);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
a a1 10a
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
|
||||
a1
|
||||
0
|
||||
0
|
||||
00 0
|
||||
1a1a1110011100a101aa11a01010a0a011a0a10a1
|
||||
1a1a1110011100a101aa11a01010a0a011a0a100a
|
||||
a1a1aaa00aaa001a0a11aa10a0a01010aa101a001
|
||||
a1a1aaa00aaa001a0a11aa10a0a01010aa101a00a
|
||||
a1a1aaa00aaa001a0a11aa10a0a01010aa101a01a
|
||||
1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
1 1
|
||||
|
||||
1
|
||||
1
|
||||
Reference in New Issue
Block a user