解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class class01 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int a=scanner.nextInt();
int num=0;
int num2=0;
for (int i = 1; i < n; i++) {
int b=scanner.nextInt();
if (a>0) {//首只蚂蚁向右
if (b<0&&Math.abs(b)>a) {//Math.abs(b)为b的绝对值
num++;
}
if (b>0&&Math.abs(b)<a) {
num2++;
}
}
if (a<0) {//首只蚂蚁向左
if (b>0&&Math.abs(b)<-a) {//Math.abs(b)为b的绝对值
num++;
}
if (b<0&&Math.abs(b)>-a) {
num2++;
}
}
}
num=num+num2;
System.out.println(num+1);//因为第一只蚂蚁也感冒了
}
}
0.0分
3 人评分
WU-图形输出 (C++代码)浏览:800 |
蚂蚁感冒 (C语言代码)浏览:768 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:635 |
A+B for Input-Output Practice (I) (C语言代码)浏览:426 |
盐水的故事 (C语言代码)浏览:1524 |
A+B for Input-Output Practice (I) (C语言代码)浏览:570 |
C二级辅导-计负均正 (C语言代码)浏览:634 |
C语言训练-最大数问题 (C语言代码)浏览:584 |
小九九 (C语言代码)浏览:500 |
用筛法求之N内的素数。 (C语言代码) 详解………………浏览:1007 |