init commit

This commit is contained in:
2025-04-13 21:48:15 +03:00
commit 23255e9121
192 changed files with 12200 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
// #include <stdio.h>
typedef int STYPE;
typedef unsigned int UTYPE;
STYPE
bit_reverse(STYPE value)
{
UTYPE result = 0;
UTYPE uvalue = (UTYPE) value;
for (int i = 0; i < sizeof(STYPE) * 8; i++) {
result <<= 1;
result |= uvalue & 1;
uvalue >>= 1;
}
return (STYPE) result;
}
// int main(void) {
// STYPE value = 0b10101010;
// STYPE result = bit_reverse(value);
// printf("%d\n", result);
// printf("%ld\n", sizeof(STYPE));
// return 0;
// }
+41
View File
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
long long res_pos = 0, res_neg = 0;
for (int i = 1; i < argc; i++) {
char *p;
errno = 0;
long long val = strtol(argv[i], &p, 10);
if (*p || errno || (int32_t) val != val || argv[i] == p) {
return 1;
}
// int32_t tmp;
if (val >= 0) {
// if (!__builtin_add_overflow(res_pos, val, &tmp)) {
res_pos += val;
// }
} else {
// if (!__builtin_add_overflow(res_neg, val, &tmp)) {
res_neg += val;
// }
}
}
// if (!(res_neg && res_pos)) {
// printf("0\n");
// } else {
// printf("%d\n", res_pos);
// printf("%d\n", res_neg);
// }
printf("%lld\n", res_pos);
printf("%lld\n", res_neg);
return 0;
}
+39
View File
@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <stdlib.h>
#include <math.h>
enum
{
PRCN = 10000,
};
int
main(int argc, char *argv[])
{
long double a = 0;
for (int i = 1; i < argc; i++) {
char *p;
errno = 0;
long double val = strtod(argv[i], &p);
if (*p || errno || argv[i] == p) {
return 1;
}
if (i == 1) {
a = val * PRCN;
} else {
a = round(a * (100.L + val) / 100.L);
}
}
if (argc == 1) {
return 1;
}
printf("%.4Lf\n", a / PRCN);
return 0;
}
+22
View File
@@ -0,0 +1,22 @@
#include <stdio.h>
enum
{
MY_INT_MAX = ~0u >> (!0),
MY_INT_MIN = ~(~0u >> (!0))
};
int
satsum(int v1, int v2)
{
int sum;
if (!__builtin_add_overflow(v1, v2, &sum)) {
return sum;
} else if (v1 > 0) {
return MY_INT_MAX;
} else {
return MY_INT_MIN;
}
return 0;
}