Vprento

9.Najdi go zbirot

Nov 9th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. int main () {
  3.     char c;
  4.     int sum = 0;
  5.     int lastDigit = 0;
  6.     while (scanf("%c", &c)) {
  7.     if (c == '!') {
  8.     break;
  9.     }
  10.     int digit = 0;
  11.     if (c>='0' && c<='9') {
  12.     digit = c - '0';
  13.     if (lastDigit) {
  14.     lastDigit *= 10;
  15.     lastDigit += digit;
  16.     sum+= lastDigit;
  17.     lastDigit = 0;
  18.     } else {
  19.     lastDigit = digit;
  20.     }
  21.     } else if (lastDigit) {
  22.     sum += lastDigit;
  23.     lastDigit = 0;
  24.     } else {
  25.     lastDigit = 0;
  26.     }
  27.     }
  28.     if (lastDigit) {
  29.     sum += lastDigit;
  30.     }
  31.     printf("%d\n", sum);
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment