Finitely generated modules over PID
Solution 1:
According to the theorem about finitely generated modules, any finitely generated module over a PID $R$ can be expressed as $$ R^r \oplus R/(p_1^{k_1}) \oplus R/(p_2^{k_2}) \oplus \cdots \oplus R/(p_n^{k_n}) $$ where $p_1^{k_1},\ldots,p_n^{k_n}$ are prime powers in $R$. The $R^r$ is called the free part, and the other summands are elementary divisors. According to the theorem, these summands are unique up to permutation.
Let $p^k$ be a prime power in $R$. Let $a$, $b$, $c$, and $d$ denote the numbers of times that $R/(p^k)$ appears as an elementary divisor of $A$, $B$, $C$, and $D$, respectively. Since $A\oplus B \cong C \oplus D$, the uniqueness part of the theorem tells us that $a+b=c+d$. Similarly, since $A\oplus D = C\oplus B$, we know that $a+d=c+b$, and it follows from these two equations that $a=c$ and $b=d$. This holds for all $p^k$, and a similar argument works for the rank of the free parts, which proves that $A\cong C$ and $B\cong D$