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.
void findIceCream(int money, int n, int cost[]) {
int i, j;
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (cost[i] + cost[j] == money) {
printf("%d %d\n", i + 1, j + 1); // 1-based index
return;
}
}
}
}
int main() {
int t;
scanf("%d", &t); // Number of trips
while (t--) {
int money, n;
scanf("%d %d", &money, &n); // Money and number of flavors
int cost[n];
for (int i = 0; i < n; i++) {
scanf("%d", &cost[i]); // Cost of each flavor
}
findIceCream(money, n, cost); // Find the two distinct flavors
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
include
void findIceCream(int money, int n, int cost[]) { int i, j; for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (cost[i] + cost[j] == money) { printf("%d %d\n", i + 1, j + 1); // 1-based index return; } } } }
int main() { int t; scanf("%d", &t); // Number of trips
}