Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- #include <ctype.h>
- /**
- Line 1: A sequence of two alphabetic characters. sep
- Line 2: A sequence of alpha-numeric characters. serie
- Example:
- >>> md
- >>> md5fg27dm5p
- Between the first letter m and the last letter d, we have the values 5 and 27.
- Thus, we obtain: 5 + 27 = 32
- Examples :
- sm
- k36sD4fs65Nd46mKv56v465dmW46d
- 636
- **/
- int main()
- {
- char sep[3];
- scanf("%[^\n]", sep); fgetc(stdin);
- char serie[256];
- scanf("%[^\n]", serie);
- int idxFirst = 0;
- int idxLast = 0;
- for (int i = 0; i < strlen(serie); i++) {
- if (serie[i] == sep[0]) {
- idxFirst = i;
- break;
- }
- }
- for (int i = strlen(serie)-1; i > 0; i--) {
- if (serie[i] == sep[1]) {
- idxLast = i;
- break;
- }
- }
- int sum = 0;
- for (int i = idxFirst; i < idxLast; i++) {
- if (isdigit(serie[i])) {
- sum += serie[i] - '0';
- }
- }
- printf("%d\n", sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement