File tree 2 files changed +27
-13
lines changed
2 files changed +27
-13
lines changed Original file line number Diff line number Diff line change @@ -44,22 +44,36 @@ int main() {
44
44
int c1 = 1 , c2 = 1 , p1 = 0 , p2 = 0 ;
45
45
s = 0 ;
46
46
while (p1 < a.size ()) {
47
- while (a[p1+c1] == a[p1+c1-1 ]) {
48
- if (c1+1 >= a.size ()) {
49
- break ;
47
+ t = 0 ;
48
+
49
+ // If both elements are equal
50
+ if (a[p1] == b[p2]) {
51
+ c1 = 1 , c2 = 1 ;
52
+ // Count how many equal elements there are in list a
53
+ while (a[p1] == a[p1+c1] && c1 < a.size ()) {
54
+ c1 += 1 ;
55
+ cout << " igual\n " ;
56
+ cout << a[p1] << " " << a[p1+c1] << " \n " ;
50
57
}
51
- c1 += 1 ;
52
- }
53
- while (b[p2+c2] == b[p2+c2-1 ]) {
54
- if (c2+1 >= b.size ()) {
55
- break ;
58
+ // Count how many equal elements there are in list b
59
+ while (b[p2] == b[p2+c2] && c2 < b.size () ) {
60
+ c2 += 1 ;
56
61
}
57
- c2 += 1 ;
62
+
63
+ cout << c1 << " " << c2 << " \n " ;
64
+ t = a[p1]*c1;
65
+ t *= c2;
66
+ s += t;
67
+ p1 += c1;
68
+ p2 += c2;
69
+ cout << t << " \n " ;
70
+ }
71
+ else if (a[p1] < b[p2]) {
72
+ p1 += 1 ;
73
+ }
74
+ else if (a[p1] > b[p2]) {
75
+ p2 += 1 ;
58
76
}
59
- s += a[p1]*b[p2];
60
- p1 += c1;
61
- p2 += c2;
62
- cout << s << " \n " ;
63
77
}
64
78
65
79
cout << s << " \n " ;
You can’t perform that action at this time.
0 commit comments