-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsjtu-oj1051.cpp
52 lines (49 loc) · 899 Bytes
/
sjtu-oj1051.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
#include <iostream>
#include <stdio.h>
using namespace std;
struct LinkedList
{
int value;
LinkedList *next;
LinkedList(int v)
:value(v), next(NULL) {}
};
int main()
{
int N;
cin >> N;
int tmpint;
LinkedList header(0);
LinkedList *cur = &header;
for (int i = 0; i < N; i++)
{
scanf("%d", &tmpint);
LinkedList *newnode = new LinkedList(tmpint);
cur->next = newnode;
cur = cur->next;
}
int M;
cin >> M;
int count = 0;
LinkedList buffer = LinkedList(0);
for (int i = 0; i < M; i++)
{
scanf("%d", &tmpint);
cur = &header;
while (cur->next != NULL)
{
count++;
if (tmpint == cur->next->value)
{
buffer.next = cur->next;
cur->next = cur->next->next;
buffer.next->next = header.next;
header.next = buffer.next;
break;
}
cur = cur->next;
}
}
cout << count << endl;
return 0;
}