Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <stdio.h>
- #include <inttypes.h>
- #include <errno.h>
- #include <stdlib.h>
- struct Elem
- {
- struct Elem *next;
- char *str;
- };
- struct Elem *dup_elem(struct Elem *head) {
- struct Elem *cur = head;
- struct Elem *pred = NULL;
- while (cur != NULL) {
- const int radix = 10;
- char *eptr;
- errno = 0;
- long long value = strtol(cur->str, &eptr, radix);
- if (!*cur->str || *eptr || errno) {
- //printf("%s\n", cur->str);
- pred = cur;
- cur = cur->next;
- } else {
- //printf("%s\n", cur->str);
- value -= 1;
- if (value == (int32_t)value) {
- struct Elem *new = malloc(8);
- new->str = malloc(30);
- new->next = cur;
- sprintf(new->str, "%d", (int32_t)value);
- if (pred == NULL) {
- head = new;
- } else {
- pred->next = new;
- }
- }
- pred = cur;
- cur = cur->next;
- }
- }
- return head;
- }
- int main() {
- char s1[20];
- char s2[20];
- char s3[20];
- scanf("%s%s%s",s1,s2,s3);
- struct Elem h1;
- h1.str = s1;
- h1.next = NULL;
- struct Elem h2;
- h2.str = s2;
- h1.next = &h2;
- struct Elem h3;
- h3.str = s3;
- h2.next = &h3;
- h3.next = NULL;
- struct Elem *head = dup_elem(&h1);
- while (head != NULL) {
- printf("%s\n", head->str);
- head = head->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement