HackAPTS - Challenges
HackAPTS - Challenges
Description:
Process a string containing nested commands to transform text based on the following rules:
Commands are processed from innermost to outermost. If the input contains invalid syntax,
output "Error".
Input Format:
Output Format:
Examples:
1. Input: {R:{A:hello}}
Output: OlLeH
Explanation:
o {A:hello} → HeLlO
o {R:HeLlO} → OlLeH
2. Input: {D:2:{R:code}}
Output: eeddoocc
Explanation:
o {R:code} → edoc
o {D:2:edoc} → eeddoocc
Constraints:
For {D:n:text}, 1 ≤ n ≤ 5
Description:
Optimize the delivery of medical supplies from a warehouse to hospitals based on their
locations, supply needs, and priority.
Hospitals with higher priority must be served first, and the delivery route must minimize travel
time. If constraints are violated, output "Error".
Input Format:
Output Format:
Examples:
1. Input:
3
0 0 100 1
10 10 50 2
20 20 75 2
1
250 40
Output:
012
30 60 105
2. Input:
4
0 0 50 1
5 5 50 1
10 10 50 2
15 15 50 2
1
250 50
Output:
0123
15 30 55 85
3. Input (Error Case):
2
0 0 300 1
10 10 200 2
1
250 40
Output:
Error
Constraints:
1 ≤ n ≤ 50 (number of hospitals).
1 ≤ m ≤ 10 (number of vehicles).
1 ≤ priority ≤ 5 (1 is highest).
0 ≤ x, y ≤ 1000 (coordinates).
1 ≤ supplies ≤ 1000.
Description:
Optimize bus routes between cities based on passenger demand, traffic patterns, and time-
based variations. The goal is to minimize travel time while maximizing passenger service. If
constraints are violated, output "Error".
Input Format:
Output Format:
2. r lines: each line contains buses (space-separated bus counts per time slot).
Examples:
1. Input:
3
0 1000
1 800
2 600
2
0 1 100 1.2
1 2 120 1.3
Output:
012
468
2. Input:
4
0 1500
1 1000
2 800
3 600
3
0 1 80 1.3
1 2 120 1.4
2 3 90 1.2
Output:
012
6 8 10
123
468
Output:
Error
Constraints:
5 ≤ n ≤ 30 (number of cities).
1 ≤ distance ≤ 1000.
#include <stdio.h>
int main() {
char input[1001];
scanf("%1000[^\n]", input);
process_string(input);
return 0;
}
C++
#include <iostream>
#include <string>
using namespace std;
int main() {
string input;
getline(cin, input);
processString(input);
return 0;
}
C#
using System;
class Program {
static void ProcessString(string input) {
// Your code goes here
}
Python
def process_string(input_string):
# Your code goes here
if __name__ == "__main__":
input_string = input().strip()
process_string(input_string)
Java
import java.util.Scanner;
JavaScript
function processString(input) {
// Your code goes here
}
Go
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadString('\n')
processString(strings.TrimSpace(input))
}
Ruby
def process_string(input)
# Your code goes here
end
input = gets.chomp
process_string(input)
TypeScript
Challenge-2:
C
#include <stdio.h>
int main() {
int n, m;
scanf("%d", &n);
int hospitals[n][4];
for (int i = 0; i < n; i++) {
scanf("%d %d %d %d", &hospitals[i][0], &hospitals[i][1], &hospitals[i][2],
&hospitals[i][3]);
}
scanf("%d", &m);
int vehicles[m][2];
for (int i = 0; i < m; i++) {
scanf("%d %d", &vehicles[i][0], &vehicles[i][1]);
}
optimize_distribution(n, m, hospitals, vehicles);
return 0;
}
C++
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n;
vector<vector<int>> hospitals(n, vector<int>(4));
for (int i = 0; i < n; i++) {
cin >> hospitals[i][0] >> hospitals[i][1] >> hospitals[i][2] >> hospitals[i][3];
}
cin >> m;
vector<vector<int>> vehicles(m, vector<int>(2));
for (int i = 0; i < m; i++) {
cin >> vehicles[i][0] >> vehicles[i][1];
}
optimizeDistribution(n, m, hospitals, vehicles);
return 0;
}
C#
using System;
using System.Collections.Generic;
class Program {
static void OptimizeDistribution(int n, int m, List<int[]> hospitals, List<int[]> vehicles)
{
// Your code goes here
}
Python
if __name__ == "__main__":
n = int(input().strip())
hospitals = [list(map(int, input().split())) for _ in range(n)]
m = int(input().strip())
vehicles = [list(map(int, input().split())) for _ in range(m)]
optimize_distribution(n, m, hospitals, vehicles)
Java
import java.util.*;
JavaScript
const fs = require('fs');
const input = fs.readFileSync(0, 'utf-8').trim().split('\n');
const n = parseInt(input[0], 10);
const hospitals = input.slice(1, n + 1).map(line => line.split(' ').map(Number));
const m = parseInt(input[n + 1], 10);
const vehicles = input.slice(n + 2).map(line => line.split(' ').map(Number));
optimizeDistribution(n, m, hospitals, vehicles);
Go
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
var n int
fmt.Scanln(&n)
hospitals := make([][]int, n)
for i := 0; i < n; i++ {
line, _ := reader.ReadString('\n')
parts := strings.Fields(line)
hospitals[i] = make([]int, 4)
for j := range parts {
hospitals[i][j], _ = strconv.Atoi(parts[j])
}
}
var m int
fmt.Scanln(&m)
vehicles := make([][]int, m)
for i := 0; i < m; i++ {
line, _ := reader.ReadString('\n')
parts := strings.Fields(line)
vehicles[i] = make([]int, 2)
for j := range parts {
vehicles[i][j], _ = strconv.Atoi(parts[j])
}
}
optimizeDistribution(n, m, hospitals, vehicles)
}
Ruby
n = gets.to_i
hospitals = Array.new(n) { gets.split.map(&:to_i) }
m = gets.to_i
vehicles = Array.new(m) { gets.split.map(&:to_i) }
optimize_distribution(n, m, hospitals, vehicles)
TypeScript
Challenge-3:
C
#include <stdio.h>
int main() {
int n, m;
scanf("%d", &n);
int cities[n][2];
for (int i = 0; i < n; i++) {
scanf("%d %d", &cities[i][0], &cities[i][1]);
}
scanf("%d", &m);
int routes[m][4];
for (int i = 0; i < m; i++) {
scanf("%d %d %d %f", &routes[i][0], &routes[i][1], &routes[i][2], &routes[i][3]);
}
optimize_bus_routes(n, m, cities, routes);
return 0;
}
C++
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n;
vector<vector<int>> cities(n, vector<int>(2));
for (int i = 0; i < n; i++) {
cin >> cities[i][0] >> cities[i][1];
}
cin >> m;
vector<vector<float>> routes(m, vector<float>(4));
for (int i = 0; i < m; i++) {
cin >> routes[i][0] >> routes[i][1] >> routes[i][2] >> routes[i][3];
}
optimizeBusRoutes(n, m, cities, routes);
return 0;
}
C#
using System;
using System.Collections.Generic;
class Program {
static void OptimizeBusRoutes(int n, int m, List<int[]> cities, List<float[]> routes) {
// Your code goes here
}
Python
if __name__ == "__main__":
n = int(input().strip())
cities = [list(map(int, input().split())) for _ in range(n)]
m = int(input().strip())
routes = [list(map(float, input().split())) for _ in range(m)]
optimize_bus_routes(n, m, cities, routes)
Java
import java.util.*;
JavaScript
const fs = require('fs');
const input = fs.readFileSync(0, 'utf-8').trim().split('\n');
const n = parseInt(input[0], 10);
const cities = input.slice(1, n + 1).map(line => line.split(' ').map(Number));
const m = parseInt(input[n + 1], 10);
const routes = input.slice(n + 2).map(line => line.split(' ').map(Number));
optimizeBusRoutes(n, m, cities, routes);
Go
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
var n int
fmt.Scanln(&n)
cities := make([][]int, n)
for i := 0; i < n; i++ {
line, _ := reader.ReadString('\n')
parts := strings.Fields(line)
cities[i] = make([]int, 2)
for j := range parts {
cities[i][j], _ = strconv.Atoi(parts[j])
}
}
var m int
fmt.Scanln(&m)
routes := make([][]float64, m)
for i := 0; i < m; i++ {
line, _ := reader.ReadString('\n')
parts := strings.Fields(line)
routes[i] = make([]float64, 4)
for j := range parts {
routes[i][j], _ = strconv.ParseFloat(parts[j], 64)
}
}
optimizeBusRoutes(n, m, cities, routes)
}
Ruby
n = gets.to_i
cities = Array.new(n) { gets.split.map(&:to_i) }
m = gets.to_i
routes = Array.new(m) { gets.split.map(&:to_f) }
optimize_bus_routes(n, m, cities, routes)
TypeScript