算法经典题型19
数列分段:给定一个整数数列,数列中连续相同的最长整数序列算成一段,问数列中共有多少段?
用到的思想—蛮力法
博主用到的环境:Win7, CodeBlocks等。
一、代码
#include<iostream>
using namespace std;
int main() {
int n, ans, before, now;
ans = 0;
before = 10000;
cin >> n;
while (n--) {
cin >> now;
if (now != before) {
ans++;
before = now;
}
}
cout << ans << endl;
return 0;
}
二、测试
总结
谢谢宝宝们的阅读,有问题的话评论@我,没问题的话点个赞再走哦~