Advertisement
Anotel

Untitled

Oct 17th, 2017
56
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. #include<string>
  3. using namespace std;
  4. int mass[11];
  5. int main() {
  6. string n;
  7. cin >> n;
  8. int ans = 0, z = 0, x = 1;
  9. for (int i = 0; i < n.size(); i++) {
  10. if (n[i] == '-') z = 1;
  11. else
  12. mass[i] = n[i] - '0';
  13. }
  14. if (z == 1) {
  15. for(int i = n.size() - 1; i > 0; i --) {
  16. ans += mass[i] * x;
  17. x = x * 10;
  18. }
  19. ans = ans * (-1);
  20. } else
  21. for(int i = n.size() - 1; i >= 0 ; i --) {
  22. ans += mass[i] * x;
  23. x = x * 10;
  24. };
  25. cout << ans;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement