#include<bits/stdc++.h>
using namespace std;
int main(){
int n, res = 0;
cin >> n;
int arr[n];
for(int i = 0; i < n; ++i)
cin >> arr[i];
for(int i = 0; i < n-1; ++i){
if(arr[i] == arr[i+1]){
++res;
++i;
}
}
cout << res << '\n';
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<bits/stdc++.h> using namespace std; int main(){ int n, res = 0; cin >> n; int arr[n]; for(int i = 0; i < n; ++i) cin >> arr[i]; for(int i = 0; i < n-1; ++i){ if(arr[i] == arr[i+1]){ ++res; ++i; } } cout << res << '\n'; } |
English