-
Notifications
You must be signed in to change notification settings - Fork 12
/
1803.cpp
77 lines (71 loc) · 1.24 KB
/
1803.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
67
68
69
70
71
72
73
74
75
76
77
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
using namespace std;
typedef struct Node
{
int num;
struct Node *next;
} Node;
Node *head;
void print(Node *p)
{
p=p->next;
printf("%d",p->num);
while(p->next!=NULL)
{
p=p->next;
printf(" %d",p->num);
}
printf("\n");
}
void ins1(Node *p,int x)
{
while(p->next!=NULL)
{
p=p->next;
}
Node *t=(Node *)malloc(sizeof(Node));
t->num=x;
t->next=p->next;
p->next=t;
}
void ins2(Node *p,int x,int y)
{
while(p!=NULL)
{
if(p->num==x)
{
Node *t=(Node *)malloc(sizeof(Node));
t->num=y;
t->next=p->next;
p->next=t;
}
p=p->next;
}
}
int main()
{
//freopen("in.txt","r",stdin);
int n,a,b;
while(scanf("%d",&n)!=EOF)
{
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
for(int i=0;i<n;i++)
{
scanf("%d",&a);
ins1(head,a);
}
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d %d",&a,&b);
ins2(head,a,b);
print(head);
}
}
return 0;
}//Parsed in 0.101 seconds