Example 3 Let $S$ be a subset of $\{1,2, \cdots, 50\}$ with the following property: the sum of any two distinct elements of $S$ is not divisible by 7. What is the maximum number of elements that $S$ can have?
(43rd American High School Mathematics Examination)
Solve: Divide $\{1,2, \cdots, 50\}$ into 7 classes according to modulo 7:
$$
\begin{array}{l}
K_{1}=\{1,8,15,22,29,36,43,50\}, \\
K_{2}=\{2,9,16,23,30,37,44\}, \\
K_{3}=\{3,10,17,24,31,38,45\}, \\
K_{4}=\{4,11,18,25,32,39,46\}, \\
K_{5}=\{5,12,19,26,33,40,47\}, \\
K_{6}=\{6,13,20,27,34,41,48\}, \\
K_{0}=\{7,14,21,28,35,42,49\} .
\end{array}
$$

Next, we prove that $S=K_{1} \cup K_{2} \cup K_{3} \cup\{7\}$ is the largest set that meets the requirements.
First, for $a, b \in S, a \neq b$, there are three possibilities:
(i) $a, b \in K_{i}(1 \leqslant i \leqslant 3)$, then $a+b \equiv 2 i(\bmod 7), a+b$ cannot be divisible by 7.
(ii) $a \in K_{i}, b \in K_{j}(1 \leqslant i \neq j \leqslant 3)$, then $a+b \equiv i+j(\bmod 7), a+b$ cannot be divisible by 7.
(iii) $a \in K_{i}, b=7(1 \leqslant i \leqslant 3)$, then $a+b \equiv i(\bmod 7), a+b$ cannot be divisible by 7. In summary, the sum of any two elements in $S$ cannot be divisible by 7.
Second, if an element $c$ is added to $S$, there must be an element in $S$ whose sum with $c$ is divisible by 7. The added $c$ has 4 possibilities:
(i) $c \in K_{4}$, then the sum of $c$ and an element in $K_{3}$ is divisible by 7.
(ii) $c \in K_{5}$, then the sum of $c$ and an element in $K_{2}$ is divisible by 7.
(iii) $c \in K_{6}$, then the sum of $c$ and an element in $K_{1}$ is divisible by 7.
(iv) $c \in K_{0}$, then the sum of $c$ and 7 is divisible by 7.
In summary, no more elements can be added to $S$. Therefore, the maximum number of elements in $S$ is
$$
|S|=\left|K_{1}\right|+\left|K_{2}\right|+\left|K_{3}\right|+1=23 \text {. }
$$