CCF认证真题-(201509-1)-数列分段

 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     ios::sync_with_stdio(false);
 6     cin.tie(0);
 7     
 8     int n;
 9     cin >> n;
10     int pre;
11     cin >> pre;
12     int ans = 1;
13     for (int i = 1; i < n; i++) {
14         int x;
15         cin >> x;
16         if (x != pre) {
17             ans++;
18             pre = x;
19         }
20     }
21     cout << ans << endl;
22     return 0;
23 }

猜你喜欢

转载自www.cnblogs.com/AntonLiu/p/11165508.html