寒假6.3

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
判斷前一位置與后一位置上數(shù)是否相同即可,相同則連續(xù),不相同及斷開(kāi)另起一列荞雏。

#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;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市晓殊,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌伤提,老刑警劉巖巫俺,帶你破解...
    沈念sama閱讀 216,843評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異肿男,居然都是意外死亡介汹,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,538評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)舶沛,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)嘹承,“玉大人,你說(shuō)我怎么就攤上這事如庭「献” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 163,187評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵柱彻,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我餐胀,道長(zhǎng)哟楷,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,264評(píng)論 1 292
  • 正文 為了忘掉前任否灾,我火速辦了婚禮卖擅,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘墨技。我一直安慰自己惩阶,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,289評(píng)論 6 390
  • 文/花漫 我一把揭開(kāi)白布扣汪。 她就那樣靜靜地躺著断楷,像睡著了一般。 火紅的嫁衣襯著肌膚如雪崭别。 梳的紋絲不亂的頭發(fā)上冬筒,一...
    開(kāi)封第一講書(shū)人閱讀 51,231評(píng)論 1 299
  • 那天恐锣,我揣著相機(jī)與錄音,去河邊找鬼舞痰。 笑死土榴,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的响牛。 我是一名探鬼主播玷禽,決...
    沈念sama閱讀 40,116評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼呀打!你這毒婦竟也來(lái)了矢赁?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,945評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤聚磺,失蹤者是張志新(化名)和其女友劉穎坯台,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體瘫寝,經(jīng)...
    沈念sama閱讀 45,367評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蜒蕾,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,581評(píng)論 2 333
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了焕阿。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片咪啡。...
    茶點(diǎn)故事閱讀 39,754評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖暮屡,靈堂內(nèi)的尸體忽然破棺而出撤摸,到底是詐尸還是另有隱情,我是刑警寧澤褒纲,帶...
    沈念sama閱讀 35,458評(píng)論 5 344
  • 正文 年R本政府宣布准夷,位于F島的核電站,受9級(jí)特大地震影響莺掠,放射性物質(zhì)發(fā)生泄漏衫嵌。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,068評(píng)論 3 327
  • 文/蒙蒙 一彻秆、第九天 我趴在偏房一處隱蔽的房頂上張望楔绞。 院中可真熱鬧,春花似錦唇兑、人聲如沸酒朵。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,692評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)蔫耽。三九已至,卻和暖如春留夜,著一層夾襖步出監(jiān)牢的瞬間针肥,已是汗流浹背饼记。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,842評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留慰枕,地道東北人具则。 一個(gè)月前我還...
    沈念sama閱讀 47,797評(píng)論 2 369
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像具帮,于是被迫代替她去往敵國(guó)和親博肋。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,654評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,322評(píng)論 0 10
  • 說(shuō)起“年味”不得不說(shuō)起小的時(shí)候蜂厅,張燈結(jié)彩匪凡,殺豬宰羊,熱氣騰騰掘猿,人聲喧鬧... 那濃濃的年味已經(jīng)變成一幅幅畫(huà)面刻在腦...
    瑾小兮閱讀 579評(píng)論 6 21
  • 親愛(ài)的梁稠通,你還好嗎衬衬? 畢業(yè)這么多年,逐漸地改橘,我們都淡出了同學(xué)的視野滋尉,而不經(jīng)意間,你卻進(jìn)入了我的夢(mèng)飞主。 每當(dāng)有外地同學(xué)...
    星韻r閱讀 334評(píng)論 1 5