寒假6.3

作者: wolfway_d0ff | 来源:发表于2019-01-30 09:17 被阅读0次

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.
Examples
Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2
判断前一位置与后一位置上数是否相同即可,相同则连续,不相同及断开另起一列。

#include<iostream>
using namespace std;
int main()
{
    int n,x=0;
    cin >> n;
    char a[100001][2];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i][0] >> a[i][1];
    }
    for (int i = 0; i < n;i++ )
    {
        if (a[i][0] == a[i + 1][0])
        {
        }
        else
        {
            x++;
        }
    }
    cout << x;
    return 0;
}

相关文章

  • 寒假6.3

    Mad scientist Mike entertains himself by arranging rows o...

  • 或许你是你,我是我

    你的他 我的他 我们的6.3 或许只是你的6.3 我的6.3 或许只是巧合 或许只是个玩笑 但我还是当真了 或许海...

  • 薅羊毛套利之高价值商品服务系列_美国主机篇 → Webhosti

    美元汇率约等于6.3 50X6.3=315元 人民币 Webhostingbuzz 官网 https://www...

  • 实验6.3 VLAN间的通信

    6.3 VLAN间的通信 ============================================...

  • 6.3

    1感谢我的小何把地拖得好干净呀2感谢小何帮我煮菜买菜,把一切打理的井井有条3感谢小何辛苦的付出 4感谢我中午有时间...

  • 6.3

    做预售已经一个月了 现在在回首看往事时 已经不算什么了 感谢我遇到的所有人 所有事 新的一周 加油

  • 6.3

    人生的旅程 需要明确的目标,永远在路上 就一定是迷路了

  • 6.3

    今天真挺对不起卢思丞的。8点完全起不来,精力管理第一步就出问题了。 今天总算总结了各种个人基本素质。而这些基本都是...

  • 6.3

    连休两天,过的好快,明天好好上班!

  • 6.3

    今早:6:00起床开始作图:一个小时做的浴室柜[憨笑] 学习了难点、疑点: 1.铺砖、波打线、踢脚线的方法 2.二...

网友评论

      本文标题:寒假6.3

      本文链接:https://www.haomeiwen.com/subject/iejqsqtx.html