Untitled

 avatar
unknown
plain_text
a month ago
1.2 kB
3
Indexable
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <cstring>
#include <cctype>


using namespace std;

int kolkuBrojki(char *str) {
int gol = strlen(str);
    int counter = 0;
for (int i=0;i<gol;i++) {
    if (isdigit(str[i])) counter++;
}
return counter;
}


void bubble(char *str, char *nova) {
   int gol = strlen(str);
    int j=0;
    for (int i=0;i<gol;i++) {
        if (isdigit(str[i])) {
            nova[j] = str[i];
            j++;
        }
    }
    nova[j]='\0';

    bool swapped;
    int golemina = strlen(nova);
    for (int i = 0; i < golemina - 1; i++) {
        swapped = false;
        for (int j = 0; j < golemina - i - 1; j++) {
            if (nova[j] > nova[j + 1]) {
                swap(nova[j], nova[j + 1]);
                swapped = true;
            }
        }

        if (!swapped)
            break;
    }

}

int main() {

char str[100];
char temp[100];
    while (cin.getline(str,100)) {
        if (*str == '#') break;

       // cout<<kolkuBrojki(str)<<":";

     bubble(str,temp);
        cout<<kolkuBrojki(str)<<":"<<temp;
        cout<<endl;
    }

        return 0;
    }
Leave a Comment