We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C
- Introduction
- "Hello World!" in C
- Discussions
"Hello World!" in C
"Hello World!" in C
Sort by
recency
|
656 Discussions
|
Please Login in order to post a comment
include
int main() {
printf("hello, world! \n"); printf("welcome to c programming");
}
//road repair question
/* 2. Road Repair | A number of points along the highway are in need of | repair. An equal number of crews are available, stationed | at various points along the highway. They must move | along the highway to reach an assigned point. Given that | one crew must be assigned to each job, what is the | minimum total amount of distance traveled by all crews | before they can begin work? | For example, given crews at points {1,3,5} and required | repairs at {3,5,7}, one possible minimum assignment | would be {1— 3,3 — 5, 5 — 7} for a total of 6 units | traveled. | Function Description | Complete the function getMinCost in the editor below. The function should return the minimum possible total | distance traveled as an integer. | getMinCost has the following parameter(s): |
crewld[crewld[0],...crewld[n-1]] : a vector of integers |
jobld[jobld[0]....jobld[n-1]] : a vector of integers |
Constraints « 1
Explanation | By index, crewld[i] — jobld[i], { (0 — 0), (1 —2),(2—4), | (3—3),(4—1)}is one possible assignment for a | minimum cost of 17. Showing element values, this is { (5 | —9,B8-3),(1-1,(4—15),(6—8)}yieldinga | total travel distance of 4+ 0+ 0+ 11 +2=17. | v Sample Case 1 | Sample Input For Custom Testing |
10 | Sample Output |
18 | Explanation | By index, {(1—0),(0—1),(2—2),(3—3)}isone | possible assignment for a minimum cost of 18. | */
include
include
include
include
include
include
include
include
include
include
char* readline(); char* ltrim(char*); char* rtrim(char*); int parse_int(char*);
// Comparison function for qsort int compare(const void* a, const void* b) { return ((int)a - (int)b); }
long getMinCost(int crew_id_count, int* crew_id, int job_id_count, int* job_id) { // Debug: Print input sizes fprintf(stderr, "crew_id_count: %d, job_id_count: %d\n", crew_id_count, job_id_count);
}
int main() { FILE* fptr = fopen(getenv("OUTPUT_PATH"), "w");
}
char* readline() { size_t alloc_length = 1024; size_t data_length = 0;
}
char* ltrim(char* str) { if (!str) { return '\0'; }
}
char* rtrim(char* str) { if (!str) { return '\0'; }
}
int parse_int(char* str) { char* endptr; int value = strtol(str, &endptr, 10);
}
include
include
include
include
include
include
include
include
include
include
define ALPHABET_SIZE 26
define MAX_SIGNATURE_LEN 100
// Node structure for our hashmap typedef struct Node { char* key; int count; struct Node* next; } Node;
define TABLE_SIZE 10007
Node* hash_table[TABLE_SIZE];
// Hash function for the signature key unsigned int hash(const char* key) { unsigned int h = 0; while (*key) { h = (h * 31 + *key++) % TABLE_SIZE; } return h; }
// Inserts or updates count in the hashmap void insert(const char* key) { unsigned int h = hash(key); Node* curr = hash_table[h];
}
// Gets count from hashmap int get(const char* key) { unsigned int h = hash(key); Node* curr = hash_table[h];
}
// Creates a frequency signature from a word void get_signature(const char* word, char* sig) { int freq[ALPHABET_SIZE] = {0}; for (int i = 0; word[i]; i++) { freq[word[i] - 'a']++; } int pos = 0; for (int i = 0; i < ALPHABET_SIZE; i++) { if (freq[i] > 0) { pos += sprintf(sig + pos, "%c%d", 'a' + i, freq[i]); } } }
// Main function to solve the problem int* stringAnagram(int dictionary_count, char** dictionary, int query_count, char** query, int* result_count) { result_count = query_count; int result = (int*)calloc(query_count, sizeof(int));
}
/* Remaining boilerplate (same as HackerRank's default) */
include
char* readline() { size_t alloc_length = 1024; size_t data_length = 0; char* data = malloc(alloc_length);
}
char* ltrim(char* str) { while (isspace(*str)) str++; return str; }
char* rtrim(char* str) { char* end = str + strlen(str) - 1; while (end >= str && isspace(*end)) end--; *(end + 1) = '\0'; return str; }
int parse_int(char* str) { return strtol(str, NULL, 10); }
int main() { FILE* fptr = fopen(getenv("OUTPUT_PATH"), "w");
}
include
include
long gcd(long a, long b) { while (b != 0) { long temp = b; b = a % b; a = temp; } return a; }
typedef struct { long num; long den; } Ratio;
int compare(const void* a, const void* b) { Ratio* r1 = (Ratio*)a; Ratio* r2 = (Ratio*)b; if (r1->num == r2->num) { if (r1->den == r2->den) return 0; return (r1->den > r2->den) ? 1 : -1; } return (r1->num > r2->num) ? 1 : -1; }
long nearlySimilarRectangles(int n, long sides[][2]) { if (n <= 1) return 0;
}
int main() { int n; int m; // not used scanf("%d", &n); scanf("%d", &m); // discard this as per input format
}
include
include
include
include
include
include
include
include
include
include
char* readline(); char* ltrim(char*); char* rtrim(char*); int parse_int(char*);
// Comparison function for qsort int compare(const void *a, const void b) { return ((int*)a - (int)b); }
/* * Complete the 'filledOrders' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER_ARRAY order * 2. INTEGER k */
int filledOrders(int order_count, int* order, int k) { qsort(order, order_count, sizeof(int), compare); // Sort the orders int count = 0; for (int i = 0; i < order_count; i++) { if (order[i] <= k) { k -= order[i]; count++; } else { break; } } return count; }
int main() { int order_count = parse_int(ltrim(rtrim(readline())));
}
// Helper functions for input parsing
char* readline() { size_t alloc_length = 1024; size_t data_length = 0;
}
char* ltrim(char* str) { while (isspace(*str)) str++; return str; }
char* rtrim(char* str) { if (*str == '\0') return str;
}
int parse_int(char* str) { return (int)strtol(str, NULL, 10); }