通过观察可知:如果整个序列全部都是连续的,输出就是0,否则输出n-1。
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, num[100005];
bool isame = true;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> num[i];
}
for (int i = 0; i < n - 1; i++)
{
if (num[i] == num[i + 1])
{
isame = true;
}
else {
isame = false;
break;
}
}
if (isame)
{
cout << 0;
}
else {
cout << n - 1;
}
return 0;
}