2. The function $f: \mathbf{R} \rightarrow \mathbf{R}$, satisfies for any real number $x$,
$$
f(1-f(x))=x \text {. }
$$
(1) Please provide a function $f$ that meets the requirement;
(2) Determine $S_{f}=\sum_{k=-2017}^{2018} f(k)$ for all possible values.
2. (1) Let
$f(x)$
$$
=\left\{\begin{array}{l}
\frac{1}{2}, \quad x=\frac{1}{2} ; \\
x+\frac{1}{2}, \quad x \in\left(k+\frac{1}{2}, k+1\right], k \in \mathbf{N} ; \\
-x+\frac{3}{2}, x \in\left(k+1, k+\frac{3}{2}\right], k \in \mathbf{N} ; \\
-x+\frac{1}{2}, x \in\left[k+\frac{1}{2}, k+1\right), k \in \mathbf{Z}, k \leqslant-1 ; \\
x-\frac{1}{2}, \quad x \in\left[k+1, k+\frac{3}{2}\right), k \in \mathbf{Z}, k \leqslant-1 .
\end{array}\right.
$$

When $x=\frac{1}{2}$,
$$
f(1-f(x))=f\left(1-\frac{1}{2}\right)=f\left(\frac{1}{2}\right)=\frac{1}{2} \text {; }
$$

When $x \in\left(k+\frac{1}{2}, k+1\right], k \in \mathbf{N}$,
$$
\begin{array}{l}
-x+\frac{1}{2} \in\left[-(k+1)+\frac{1}{2},-(k+1)+1\right), \\
f(1-f(x))=f\left(1-\left(x+\frac{1}{2}\right)\right) \\
=f\left(-x+\frac{1}{2}\right)=-\left(-x+\frac{1}{2}\right)+\frac{1}{2} \\
=x ;
\end{array}
$$

When $x \in\left(k+1, k+\frac{3}{2}\right], k \in \mathbf{N}$,
$$
\begin{array}{l}
x-\frac{1}{2} \in\left(k+\frac{1}{2}, k+1\right], \\
f(1-f(x))=f\left(1-\left(-x+\frac{3}{2}\right)\right) \\
=f\left(x-\frac{1}{2}\right)=\left(x-\frac{1}{2}\right)+\frac{1}{2} \\
=x
\end{array}
$$

When $x \in\left[k+\frac{1}{2}, k+1\right), k \in \mathbf{Z}, k \leqslant-1$,
$$
\begin{array}{l}
x+\frac{1}{2} \in\left[k+1, k+\frac{3}{2}\right), \\
f(1-f(x))=f\left(1-\left(-x+\frac{1}{2}\right)\right) \\
=f\left(x+\frac{1}{2}\right)=\left(x+\frac{1}{2}\right)-\frac{1}{2}=x ;
\end{array}
$$

When $x \in\left[k+1, k+\frac{3}{2}\right), k \in \mathbf{Z}, k \leqslant-1$,
$$
\begin{array}{l}
\frac{3}{2}-x \in\left(-(k+1)+1,-(k+1)+\frac{3}{2}\right], \\
f(1-f(x))=f\left(1-\left(x-\frac{1}{2}\right)\right) \\
=f\left(\frac{3}{2}-x\right)=-\left(\frac{3}{2}-x\right)+\frac{3}{2} \\
=x .
\end{array}
$$
(2) Since $f(1-f(x))=x$, we have,
$$
f(1-x)=f(1-f(1-f(x))=1-f(x) \text {, }
$$

i.e., $f(1-x)+f(x)=1$.
Thus, $S_{f}=\sum_{k=1}^{2018}(f(1-k)+f(k))=2018$.