The time-dependent $C!P$ asymmetries in $B^0topi^+pi^-$ and $B_s^0to K^+!K^-$ decays are measured using a data sample of $pp$ collisions corresponding to an integrated luminosity of 3.0 fb$^{-1}$, collected with the LHCb detector at centre-of-mass energies of 7 and 8 TeV. The same data sample is used to measure the time-integrated $C!P$ asymmetries in $B^0to K^+pi^-$ and $B_s^0topi^+ K^-$ decays. The results are $C_{pi^+pi^-} = -0.34 pm 0.06 pm 0.01$, $S_{pi^+pi^-} = -0.63 pm 0.05 pm 0.01$, $C_{K^+!K^-} = 0.20 pm 0.06 pm 0.02$, $S_{K^+!K^-} = 0.18 pm 0.06 pm 0.02$, $C_{K^+!K^-}^{DeltaGamma} = -0.79 pm 0.07 pm 0.10$, $A_{C!P}^{B^0} = -0.084 pm 0.004 pm 0.003$, and $A_{C!P}^{B_s^0} = 0.213 pm 0.015 pm 0.007$, where the first uncertainties are statistical and the second systematic. Evidence for $C!P$ violation is found in the $B_s^0to K^+!K^-$ decay for the first time.