Language: C++

import Data.Char -- for words func.
import Control.Monad -- for forM_ replicateM func.

type Vector = (Double, Double)
type Scalar = Double

---------------------------------------------------
-- alithmetic functions for vector calculations. --
---------------------------------------------------
vadd :: Vector -> Vector -> Vector
vadd (x, y) (z, w) = (x + z, y + w)

vsub :: Vector -> Vector -> Vector
vsub (x, y) (z, w) = (x - z, y - w)

vdot :: Vector -> Vector -> Scalar
-- vdot defines dot product for 2D vector.
vdot (x, y) (z, w) = x * z + y * w

smul :: Scalar -> Vector -> Vector
-- smul defines scalar multiplication of 2D vector.
smul a (x, y) = (a * x, a * y)

sqnorm :: Vector -> Scalar
-- calculate squared euclidean norm(sqnorm(x) = ||x||^2).
sqnorm (x, y) = x * x + y * y

projection_point :: Vector -> Vector -> Vector -> Vector
-- find the projection point when p_1, p_2, p are geven.
-- p_1, p_2 are the point on a straight line called l.
-- projection point are defined as the point on the l
-- is the most close to point p.
projection_point p_1 p_2 p
  | p_1 /= p_2 = (a `vdot` b / sqnorm a) `smul` a `vadd` p_1
  | otherwise  = p_1
  where
    a = p_2 `vsub` p_1
    b = p `vsub` p_1

--------------------------------------
-- functions for string formatting. --
--------------------------------------
line2ps :: String -> [Vector]
-- this function formatting line include p_1 and p_2 value
-- to list of p_1 and p_2.
-- e.g.
-- input: "0 0 2 0" -- i.e. "p_1x p_1y p_2x p_2y"
-- output: [(0, 0), (2, 0)] -- i.e. [p_1, p_2]
line2ps line = [p_1, p_2]
  where
    ps = words line
    p_1 = line2p . unwords $ take 2 ps
    p_2 = line2p . unwords $ drop 2 ps

line2p :: String -> Vector
-- transform string to vector.
-- input: "0 1" -- i.e. "p_x p_y"
-- output: (0, 1)
line2p line = p
  where
    ps = words line
    p_x = read (ps!!0) :: Double
    p_y = read (ps!!1) :: Double
    p = (p_x, p_y)

vec2line :: Vector -> String
vec2line (x, y) = show x ++ " " ++  show y

---------------------
-- main statement. --
---------------------
main :: IO()
main = do
  ps <- getLine
  q  <- getLine
  plist <- replicateM (read q) getLine
  let proj p = (take 10) . vec2line $ projection_point ((line2ps ps)!!0) ((line2ps ps)!!1) (line2p p) in putStrLn . init . unlines $ map proj plist



Compiler output:
a.cc:34:21: error: stray '`' in program
   34 |   | p_1 /= p_2 = (a `vdot` b / sqnorm a) `smul` a `vadd` p_1
      |                     ^
a.cc:34:26: error: stray '`' in program
   34 |   | p_1 /= p_2 = (a `vdot` b / sqnorm a) `smul` a `vadd` p_1
      |                          ^
a.cc:34:42: error: stray '`' in program
   34 |   | p_1 /= p_2 = (a `vdot` b / sqnorm a) `smul` a `vadd` p_1
      |                                          ^
a.cc:34:47: error: stray '`' in program
   34 |   | p_1 /= p_2 = (a `vdot` b / sqnorm a) `smul` a `vadd` p_1
      |                                               ^
a.cc:34:51: error: stray '`' in program
   34 |   | p_1 /= p_2 = (a `vdot` b / sqnorm a) `smul` a `vadd` p_1
      |                                                   ^
a.cc:34:56: error: stray '`' in program
   34 |   | p_1 /= p_2 = (a `vdot` b / sqnorm a) `smul` a `vadd` p_1
      |                                                        ^
a.cc:37:13: error: stray '`' in program
   37 |     a = p_2 `vsub` p_1
      |             ^
a.cc:37:18: error: stray '`' in program
   37 |     a = p_2 `vsub` p_1
      |                  ^
a.cc:38:11: error: stray '`' in program
   38 |     b = p `vsub` p_1
      |           ^
a.cc:38:16: error: stray '`' in program
   38 |     b = p `vsub` p_1
      |                ^
a.cc:1:1: error: 'import' does not name a type
    1 | import Data.Char -- for words func.
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'