解题思路:
注意事项:
参考代码:
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 人评分