AcWing 1211. 蚂蚁感冒
原题链接
简单
作者:
suchong
,
2024-03-13 20:33:18
,
所有人可见
,
阅读 9
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110;
int x[N];
int n;
int main()
{
cin>>n;
for(int i=0; i<n; i++) cin>>x[i];
int left=0,right=0;//分别表示左边向右走的和右边向左走的
for(int i=1; i<=n; i++)
{
if(abs(x[i])<abs(x[0]) && x[i]>0) left++;
else if(abs(x[i])>abs(x[0]) && x[i]<0) right++;
}
if(left==0&&x[0]<0) cout<<1;
else if(right==0&&x[0]>0) cout<<1;
else cout<<left+right+1;
return 0;
}