AcWing 1211. 蚂蚁感冒
原题链接
简单
作者:
再给我一次AC的机会
,
2024-03-05 18:01:39
,
所有人可见
,
阅读 20
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 55;
int arr[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, left = 0, right = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
for (int i = 1; i < n; i++)
{
if (abs(arr[i]) < abs(arr[0]) && arr[i] > 0)
{
left++;
}
else if (abs(arr[i] )> abs(arr[0]) && arr[i] < 0)
{
right++;
}
}
if (right == 0 && arr[0] > 0 || left == 0 && arr[0] < 0)cout << 1;
else cout << left + right + 1;
return 0;
}