AcWing 1211. 蚂蚁感冒
原题链接
简单
作者:
Bug-Free
,
2020-03-22 21:29:54
,
所有人可见
,
阅读 692
#include <cmath>
#include <iostream>
using namespace std;
const int N = 55;
int n;
int x[N];
int main(void)
{
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", &x[i]);
int leftToright = 0, rightToleft = 0;
for(int i = 0; i < n; i++)
{
if(abs(x[i]) < abs(x[0]) && x[i] > 0) leftToright++;
if(abs(x[i]) > abs(x[0]) && x[i] < 0) rightToleft++;
}
if(x[0] > 0 && rightToleft == 0 || x[0] < 0 && leftToright == 0)
puts("1");
else
printf("%d\n", leftToright + rightToleft + 1);
return 0;
}