-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDUT 2120.cpp
66 lines (64 loc) · 1.53 KB
/
SDUT 2120.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<iostream>
using namespace std;
typedef struct node
{
int data;
struct node *next;
}Node;
void sort_divide(Node *head,Node *head_1,Node *head_2)
{
Node *cur,*prev_1,*prev_2;
prev_1 = head_1;
prev_2 = head_2;
for(cur=head->next;cur!=NULL;)
{
if(cur->data%2==0)
{
prev_1->next = cur;
prev_1 = cur;
cur=cur->next;
}
else
{
prev_2->next = cur;
prev_2 = cur;
cur = cur ->next;
}
}
prev_1 ->next = NULL;
prev_2 ->next = NULL;
}
int main()
{
int n;scanf("%d",&n);
Node *head,*cur,*prev;
prev = (Node*)malloc(sizeof(Node));
head = prev;
for(int i = 0;i<n;i++)
{
cur = (Node*)malloc(sizeof(Node));
scanf("%d",&cur->data);
prev ->next = cur;
prev = cur;
}
cur->next = NULL;
Node *head_1,*head_2;
head_1 = (Node*)malloc(sizeof(Node));
head_2 = (Node*)malloc(sizeof(Node));
sort_divide(head,head_1,head_2);
int count_1 = 0,count_2 = 0;
for(cur = head_1->next;cur!=NULL;cur=cur->next) count_1++;
for(cur = head_2->next;cur!=NULL;cur=cur->next) count_2++;
printf("%d %d\n",count_1,count_2);
for(cur = head_1->next;cur!=NULL;cur=cur->next)
{
if(cur->next!=NULL) printf("%d ",cur->data);
else printf("%d\n",cur->data);
}
for(cur = head_2->next;cur!=NULL;cur=cur->next)
{
if(cur->next!=NULL) printf("%d ",cur->data);
else printf("%d\n",cur->data);
}
return 0;
}