Advertisement
STANAANDREY

18/151

Oct 29th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <stdio.h>
  4. #include <ctype.h>
  5. #include <stdlib.h>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     char s[256][256];
  11.     int n, sum = 0, k = 0;
  12.     cin >> n;
  13.     for (int i = 0; i < n; i++)
  14.         cin >> s[i];
  15.  
  16.     for (int i = 0; i < n; i++)
  17.     {
  18.         int ok = 1, neg = 0;
  19.         if (s[i][0] == '-')
  20.         {
  21.             neg = 1;
  22.             strcpy(s[i], s[i] + 1);
  23.         }
  24.  
  25.         for (int j = 0; s[i][j] && ok; j++)
  26.             if (!isdigit(s[i][j]))
  27.                 ok = 0;
  28.  
  29.         if (ok)
  30.         {
  31.             int nr = atoi(s[i]);
  32.             if (neg)
  33.                 nr = -nr;
  34.             sum += nr;
  35.         }
  36.         else
  37.             k++;
  38.     }
  39.  
  40.     cout << k << ' ' << sum;
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement