init commit
This commit is contained in:
Executable
+19
@@ -0,0 +1,19 @@
|
||||
enum
|
||||
{
|
||||
MY_INT_MAX = ~0u >> (!0),
|
||||
MY_INT_MIN = ~(~0u >> (!0))
|
||||
};
|
||||
|
||||
int
|
||||
satsum(int v1, int v2)
|
||||
{
|
||||
if (v1 > 0 && (signed int) MY_INT_MAX - v1 < v2) {
|
||||
return MY_INT_MAX;
|
||||
}
|
||||
|
||||
if (v1 < 0 && (signed int) MY_INT_MIN - v1 > v2) {
|
||||
return MY_INT_MIN;
|
||||
}
|
||||
|
||||
return v1 + v2;
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
enum
|
||||
{
|
||||
CHAR_IN_INT = 12
|
||||
};
|
||||
|
||||
struct Elem
|
||||
{
|
||||
struct Elem *next;
|
||||
char *str;
|
||||
};
|
||||
|
||||
struct Elem *
|
||||
dup_elem(struct Elem *head)
|
||||
{
|
||||
if (head == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
head->next = dup_elem(head->next);
|
||||
|
||||
errno = 0;
|
||||
char *p;
|
||||
long n = strtol(head->str, &p, 10);
|
||||
if (errno || (int) n != n || n == INT_MAX || *p || p == head->str) {
|
||||
return head;
|
||||
}
|
||||
|
||||
struct Elem *new = calloc(1, sizeof(*new));
|
||||
if (new == NULL) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *str = calloc(CHAR_IN_INT, sizeof(*str));
|
||||
snprintf(str, CHAR_IN_INT, "%d", (int) n + 1);
|
||||
|
||||
new->str = str;
|
||||
new->next = head;
|
||||
|
||||
return new;
|
||||
}
|
||||
Reference in New Issue
Block a user