jerry.a.yin
BAN USERSuppose this array is sorted. coding as below.
#include <stdio.h>
#define ARRAY_NULL 1
int main(int argc, char **argv){
if(array = NULL){
return ARRAY_NULL;
}
int first_int = 0;
int second_int = 0;
int length;
length = sizeof(array);
for(int i = 0; i < length; i++){
if(i % 2){
first_int = first_int * 10 + array[i];
}
else{
second_int = second_int * 10 + array[i];
}
}
printf("The least sum number is : %d = %d + %d\n", first_int+second_int, first_int, second_int);
return 0;
}
I think this question check if you could use thread synchronization.
1. Create thread for each link.
2. Create a variable for record ID, after there is thread read then do self-increasing. And set thread lock for it to avoid access conflict.
Suppose this array is sorted. coding as below.
- jerry.a.yin December 04, 2013#include <stdio.h>
#define ARRAY_NULL 1
int main(int argc, char **argv){
if(array = NULL){
return ARRAY_NULL;
}
int first_int = 0;
int second_int = 0;
int length;
length = sizeof(array);
for(int i = 0; i < length; i++){
if(i % 2){
first_int = first_int * 10 + array[i];
}
else{
second_int = second_int * 10 + array[i];
}
}
printf("The least sum number is : %d = %d + %d\n", first_int+second_int, first_int, second_int);
return 0;
}
If this array not be sorted, we will sort it first.