问个面试题# JobHunting - 待字闺中
B*1
1 楼
不知道哪个公司的
Write a function
int triangle(int A[], int n);
which given a zero-indexed array A of n integers returns 1 if there exists
triple i,j,k ($i\not=j\not=k$, $0\le i,j,k A[i] + A[j] > A[k]
A[i] + A[k] > A[j]
A[j] + A[k] > A[i]
or returns 0 otherwise.
Examples:
For:
A[0]=10, A[1]=2, A[2]=5, A[3]=1, A[4]=8, A[5]=20
your function should return 1, since for i=0,j=2,k=4 all conditions are
fullfiled (i.e. A[2]+A[4]>A[0]).
For:
A[0]=10, A[1]=50, A[2]=5, A[3]=1
your function should return 0.
Write a function
int triangle(int A[], int n);
which given a zero-indexed array A of n integers returns 1 if there exists
triple i,j,k ($i\not=j\not=k$, $0\le i,j,k
A[i] + A[k] > A[j]
A[j] + A[k] > A[i]
or returns 0 otherwise.
Examples:
For:
A[0]=10, A[1]=2, A[2]=5, A[3]=1, A[4]=8, A[5]=20
your function should return 1, since for i=0,j=2,k=4 all conditions are
fullfiled (i.e. A[2]+A[4]>A[0]).
For:
A[0]=10, A[1]=50, A[2]=5, A[3]=1
your function should return 0.