zad8

 avatar
user_1041599
c_cpp
a month ago
860 B
1
Indexable
2kolok_SP
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;

bool hasDigits(char *s, int len) {
    int count = 0;
    for (int i = 0; i < len; i++) {
        if (isdigit(s[i]))
            count++;
    }
    return count >= 2;
}

int main() {
    char s[101];
    char max[101];
    int maxLen = 0;
    while (cin.getline(s, 100)) {
        if (*s=='0')
            break;
        int len = strlen(s);
        if (hasDigits(s,len) and len >= maxLen) {
            maxLen = len;
            strcpy(max, s);
        }
    }
    const char* start = nullptr;
    const char* end = nullptr;

    for (const char* p = max; *p != '\0'; p++) {
        if (isdigit(*p)) {
            if (!start) {
                start = p;
            }
            end = p;
        }
    }
    for (const char* p = start; p <= end; p++) {
        cout<<*p;
    }
}
Leave a Comment