Description

Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.

Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.

Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.

Output

On the single line of the output print the number of groups of magnets.

Sample Input

Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2

Hint

The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.

The second testcase has two groups, each consisting of two magnets.

题意:给你一个数n,表示接下来会有n行 01或者 10,0表示磁极的正级,1,表示磁极的负极,目的是让你把这n个01或者10连接成一个字符串,判断这个字符串有多少快组成,也就是说有多少各连续的1,1或者0,0把这个长串分成了几个部分。。。

分析: 简单模拟,瞎搞。

code:

 /*************************************************************************
> File Name: cf.cpp
> Author: PrayG
> Mail:
> Created Time: 2016年07月10日 星期日 12时57分34秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int maxn = ;
string arr;
int main()
{
string str;
int n,ans= ;
cin >> n;
for(int t = ; t <= n; t++)
{
str.clear();
cin >> str;
if(t == )
{
arr += str;
}
else
{
int len = arr.length();
// printf("len = %d\n",len);
// cout <<"str = " << str << endl;
if(arr[len-] == str[])
{
//cout << "arr = " << arr << endl;
ans++;
}
arr += str;
}
}
cout << ans << endl;
return ;
}

最新文章

  1. 拥抱.NET Core,跨平台的轻量级RPC:Rabbit.Rpc
  2. bootstrap弹框
  3. JSBinding / Memory Management (GC)
  4. Oracle 怎么让id自增加
  5. Codevs 1904 最小路径覆盖问题
  6. getchar()与EOF
  7. 实现简易版的moment.js
  8. Ubuntu彻底删除/卸载mysql,php,apache
  9. JavaScript模块化 --- Commonjs、AMD、CMD、es6 modules
  10. C++一个类对象的大小计算
  11. 怎么使用小程序的data-*属性?
  12. 十、uboot 代码流程分析---run_main_loop
  13. plsql developer日期类型数据格式不对如何设置?
  14. Forward+ Shading架构
  15. [No0000174]Spring常用注解(收藏大全)
  16. D Tree Requests dfs+二分 D Pig and Palindromes -dp
  17. thinkphp中的AJAX返回ajaxReturn()
  18. MathType调整矩阵分隔线粗细的方法
  19. python的输出问题
  20. JDK源码学习之 java.util.concurrent.automic包

热门文章

  1. Oracle学习总结(7)—— 常用的数据库索引优化语句总结
  2. 与Greenplum度过的三个星期
  3. opencv矩阵运算(2)
  4. [Perl系列—] 2. Perl 中的引用使用方法
  5. An existing connection was forcibly closed by the remote host
  6. 递归神经网络——就是解决AST这样的问题
  7. nyoj--42--一笔画问题(并查集)
  8. matplotlib 可视化 —— 移动坐标轴(中心位置)
  9. Mvc 返回文件直接下载
  10. hive parquet table 配置使用压缩