to calculate formal charge = total number of valence electrons in the free atom- Total number of lone pair-1/2 total number of shared pair.
As in example of O3
We know O atom in free state has 1s2,2s2,2px2,2py12pz1
But in valence shell it is 2s2,2px2,2py1,2pz1
As the numbering is given . let us take Oxygen with number1
total number of valence electrons in free state is =6 (as calculated above)
Total number of non-bonding electrons=2as lone pair we can see
Number of bonding electrons= as we know for formation of one bond two electrons are required so calculate the bonds formed and multiply it by2= 3x2=6
This way we can calculate charge on each atom .