41 lines
843 B
C
41 lines
843 B
C
#include "./twoSum.c"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define USAGE "Usage: twoSum -t <target> <e0> <e1> [...<es>]\n"
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if (argc < 5) {
|
|
fprintf(stderr, USAGE);
|
|
return 1;
|
|
}
|
|
if (strcmp("-t", argv[1]) != 0) {
|
|
fprintf(stderr, USAGE);
|
|
return 1;
|
|
}
|
|
int target = atoi(argv[2]);
|
|
int *nums = malloc(sizeof(int) * (argc - 3));
|
|
|
|
for (int i = 3; i < argc; i++) {
|
|
nums[i - 3] = atoi(argv[i]);
|
|
}
|
|
|
|
int returnSize = 0;
|
|
int *result = twoSum(nums, argc - 3, target, &returnSize);
|
|
|
|
if (!returnSize) {
|
|
fprintf(stderr, "Did not find two indices.");
|
|
return 1;
|
|
}
|
|
|
|
for (int i = 0; i < returnSize; i++) {
|
|
printf("%i ", result[i]);
|
|
}
|
|
printf("\n");
|
|
|
|
free(result);
|
|
free(nums);
|
|
|
|
return 0;
|
|
}
|