rt,我用如下代码拿了满分
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[100005],x,y,ans;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]==1)
{
if(x==0)
x=i;
y=max(y,i);
ans++;
}
}
for(int i=1;i<x;i++)
if(a[i]==2)
{
ans++;
break;
}
for(int i=y+1;i<=n;i++)
if(a[i]==3)
{
ans++;
break;
}
cout<<ans;
return 0;
}
但如果输入的数全是2,答案应该是1,我的输出却是0。