https://www.hackerrank.com/challenges/30-review-loop/problem
Задача Заданная строка, S , длиной N , которая проиндексирована от 0 до
N -1, печатать его четные и нечетные символы как 2 строки, разделенные пробелом, в одной строке (см. Пример ниже для
подробнее).
Примечание: 0 считается четным индексом.
Формат ввода
В первой строке записано целое число, T (количество тестовых случаев).
Каждая строка последующих строк содержит строку, S .
Ограничения
- 1 <= <em>T <= 10 </li>
- 2 <= длина <em>S <= 10000 </li>
Формат вывода
Для каждой строки S j (где 0 <= <em>j <= <em>T -1), распечатать
S j - четные символы, затем пробел, за которыми следуют S j нечетные символы.
Пример ввода
2
Hacker
Rank
Образец Ouput
Hce akr
Rn ak
Мой код
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define b 10000
struct st * create();
void insert(struct st * , char *);
void display(struct st *);
struct st {
char a[b];
int si;
struct st *prev,*next;
};
int main() {
struct st *l;
int i,n;
char d,sam[b];
scanf("%d",&n);
printf("aaaaaaaaaa");
scanf("%c",&d);
for(i=0;i<n;i++) {
//printf("bbbbbbbbbbbb");
fgets(sam,b,stdin);
//printf("ccccccccc");
printf("%s",sam);
//printf("dddddddddddd");
insert(l,sam);
//printf("eeeeeeeeeeeeeee");
}
display(l);
}
struct st * create() {
struct st *x;
x=malloc(sizeof(struct st));
x->prev=x->next=x;
return x;
}
void insert(struct st * l, char s[b]) {
//printf("------------------");
struct st *temp=create();
strcpy(temp->a,s);
temp->si=strlen(s);
temp->prev=l->prev;
temp->next=l;
l->prev->next=temp;
l->prev=temp;
}
void display(struct st *l) {
int x,p;
struct st *u;
u=l->next;
while(u!=l) {
for(p=0;p<(u->si);p++) {
if(p%2==0)
printf("%c",u->a[p]);
if(p%2==1)
printf("%c",u->a[p]);
}
u=u->next;
}
}
Я получаю ошибку сегментации после чтения строки внутри цикла