Top.Mail.Ru
Ответы

Задан текст. Напечатать все слова, содержащие две рядом стоящие цифры

Задан текст. Напечатать все слова, содержащие две рядом стоящие цифры
на языке С
помогите написать код с блок схемой

По дате
По рейтингу
Аватар пользователя
Новичок
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
 #include <ctype.h> 
#include <stdbool.h> 
#include <stdio.h> 
#include <string.h>

#define BUFFER 0x1000

_Bool is_couple_of_numbers(const char* pair) { 
    int first, second; 
    if (strlen(pair) < 2) return false; 
    first = pair[0]; 
    second = pair[1]; 
    return first > 0 && second > 0  
        && isdigit(first) && isdigit(second); 
}

_Bool is_meets_the_condition(char* word) { 
    char pair[3] = {0}; 
    char* it = &word[0]; 
    char* end = &word[strlen(word) - 1]; 
    while (it < end) { 
        strncpy(pair, it, 2); 
        ++it; 
        if (is_couple_of_numbers(pair)) { 
            return true; 
        } 
    } 
    return false; 
}

int main(void) { 
    const char* delim = " "; 
    char* word = NULL; 
    char line[BUFFER]; 
    fgets(line, BUFFER, stdin); 
    line[strlen(line) - 1] = 0; 
    word = strtok(line, delim); 
    if (is_meets_the_condition(word)) { 
        puts(word); 
    } 
    while ((word = strtok(NULL, delim)) != NULL) { 
        if (is_meets_the_condition(word)) { 
            puts(word); 
        } 
    } 
    return 0; 
}