Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main () {
- char c;
- int sum = 0;
- int lastDigit = 0;
- while (scanf("%c", &c)) {
- if (c == '!') {
- break;
- }
- int digit = 0;
- if (c>='0' && c<='9') {
- digit = c - '0';
- if (lastDigit) {
- lastDigit *= 10;
- lastDigit += digit;
- sum+= lastDigit;
- lastDigit = 0;
- } else {
- lastDigit = digit;
- }
- } else if (lastDigit) {
- sum += lastDigit;
- lastDigit = 0;
- } else {
- lastDigit = 0;
- }
- }
- if (lastDigit) {
- sum += lastDigit;
- }
- printf("%d\n", sum);
- return 0;
- }
Add Comment
Please, Sign In to add comment