Description
n 块磁铁排成一排,磁铁有两种状态,01和10分别表示正极的不同方向,问最后这些磁铁会变成几段
Input
第一行一整数
Output
输出这些磁铁最后会分成多少段
Sample Input
6
10
10
10
01
10
10
Sample Output
3
Solution
水题,只要相邻两个磁铁的状态不用则段数加一
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
int n,a[maxn];
int main()
{
while(~scanf("%d",&n))
{
int num=1;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=2;i<=n;i++)if(a[i]!=a[i-1])num++;
printf("%d\n",num);
}
return 0;
}