Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. string str;
  6. int a,b,c;
  7. int esum = 0, osum = 0;
  8. cin>>str;
  9. c=str.size();
  10. int arr[c];
  11. b=0;
  12. while(b!=c)
  13. {
  14. arr[b]=str[b]-'0' ;//the subtraction of ‘0’ is essential,thats what converts it to a number
  15. if(b % 2 == 0){
  16. esum += arr[b];
  17. }else{
  18. osum += arr[b];
  19. }
  20. b++;
  21. }
  22.  
  23. // The entire array
  24. for(int i = 0; i<b; i++){
  25. cout<<arr[i]<<endl;
  26. }
  27.  
  28. // The difference
  29. cout<<esum - osum;
  30.  
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement