A - Magnets
Problem Link: Codeforces 344A
#include<iostream>
#include<vector>
using namespace std;
int main (){
int n;
cin>>n;
int arr[n],i,count=1;
for (i =0; i<n;i++)
cin>>arr[i];
for (int j=0 ;j<n-1;j++){
if (arr[j]!=arr[j+1])
count++;
}
cout<<count<<endl;
return 0;
}
n = int(input())
a = []
z = 0
for i in range(1, n + 1):
a.append(input())
if i > 1:
if a[i - 1] != a[i - 2]:
z += 1
print(z + 1)
import java.util.Scanner;
public class Main
{
public static void main(String args[] )
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int temp = 1;
String temp1 = sc.next();
for(int i=1; i<n; i++){
String s = sc.next();
if(i%2==0){
if(s.equals(temp1)){}
else {temp++; temp1 =s; }
}
else{
if(s.equals(temp1)){}
else {temp++; temp1 =s; }
}
}
System.out.println(temp);
}
}