解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class T1454{ public static boolean IsCross(int a,int b){ if(a>0&&b<0&&Math.abs(a)<Math.abs(b) || a<0&&b>0&&Math.abs(a)>Math.abs(b)) return true; return false; } public static void main(String []args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ int n = in.nextInt(); int []a = new int[n]; int cnt = 1,flag = 0,j = -1; a[0] = in.nextInt(); for(int i = 1;i<n;i++){ a[i] = in.nextInt(); if(IsCross(a[0],a[i])) { cnt++; if(flag == 0) flag = 1;j = i; } } for(int i = 0;i<n&&flag == 1;i++) if(IsCross(a[j],a[i])) cnt++; System.out.println(cnt-1); } in.close(); } }
0.0分
1 人评分
【绝对值排序】 (C语言代码)浏览:717 |
c primer plus 第十二章 12.1小节浏览:377 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:798 |
简单的a+b (C语言代码)浏览:488 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:588 |
C二级辅导-统计字符 (C语言代码)浏览:481 |
简单的a+b (C语言代码)浏览:630 |
简单的a+b (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:519 |
杨辉三角 (C语言代码)浏览:679 |