-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1228.cpp
More file actions
48 lines (40 loc) · 806 Bytes
/
Copy path1228.cpp
File metadata and controls
48 lines (40 loc) · 806 Bytes
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
#include <bits/stdc++.h>
using namespace std;
void printVet(int *v, int n) {
printf("\n");
for (int i = 0; i < n; i++) printf(" %d ", v[i]);
printf("\n");
}
int main() {
int a,*b,*c, pos, aux,flag, count;
while(scanf("%d",&a) != EOF){
c = (int *) malloc(a * sizeof(int));
b = (int *) malloc(a * sizeof(int));
count = 0;
flag = 0;
memset(c, 0, a);
memset(b, 0, a);
for (int i = 0; i < a; i++){
scanf("%d", &b[i]);
}
for (int i = 0; i < a; i++) {
scanf("%d", &c[i]);
}
for (int i = 0; i < a; i++) {
pos = i;
for (int j = 0; j < a; j++) {
if (c[i] == b[j] && i != j) {
pos = j;
count++;
}
}
aux = c[i];
c[i] = c[pos];
c[pos] = aux;
}
//if (count > 0) count--;
printf("%d\n", count);
printVet(c, a);
}
return 0;
}