Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<iostream>
using namespace std;
int main(){
int n, count = 1;
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]){
count++;
}
}
cout<<count;
}
Copy The Code &
Try With Live Editor
Input
6
10
10
10
01
10
10
10
10
10
01
10
10
Output
4
01
01
10
10
01
01
10
10
Demonstration
Codeforcess Solution 344-A A. Magnets ,C++, Java, Js and Python ,344-A,Codeforcess Solution