Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- //////////////////
- const int SIZE = 50;
- char text[SIZE];
- int i = 0;
- /////////////////
- void toPrint(long double *arr, long double len)
- {
- for (int i = 0; i < len; i++)
- cout << arr[i] << " ";
- }
- /////////////////
- void toSort(long double *arr, long double len)
- {
- for (int i = 0; i < len; i++)
- {
- int tempo = arr[0];
- for (int j = i + 1; j < len; j++)
- {
- if (arr[i] > arr[j])
- {
- tempo = arr[i];
- arr[i] = arr[j];
- arr[j] = tempo;
- }
- }
- }
- }
- /////////////////
- int size(char txt[])
- {
- long double n = 0;
- for (i = 0; i < strlen(txt); i++)
- {
- if ((isdigit(txt[i])))
- {
- while (i < strlen(txt))
- {
- if (txt[i] == '.')
- i++;
- if (!isdigit(txt[i]))
- break;
- i++;
- }
- n++;
- }
- }
- return n;
- }
- /////////////////
- long double* toFind(char txt[], int n)
- {
- long double *array = new long double[n];
- int k = 0, c = 0;
- i = 0;
- for (i = 0; i < strlen(txt); i++)
- {
- char *temp = new char[SIZE];
- if (txt[i]!='.' && !isdigit(txt[i]) && isdigit(txt[i + 1]))
- {
- if(txt[i]!='.' && txt[i]=='-' && isdigit(txt[i+1]))
- {
- for (int r = i; r < strlen(txt); r++)
- {
- temp[k] = txt[r];
- k++;
- }
- array[c] = atof(temp);
- c++;
- }
- for (int r = i + 1; r < strlen(txt); r++)
- {
- temp[k] = txt[r];
- k++;
- }
- array[c] = atof(temp);
- c++;
- }
- delete [] temp;
- k = 0;
- }
- toSort(array, n);
- return array;
- }
- //////////////
- int main()
- {
- cout << "Write your text: "; cin.getline(text, SIZE, '&');
- cout << "Your text: " << text << endl;
- //ARRAY//
- int sz = size(text);
- long double *array = new long double[sz];
- //FILL IN ARRAY//
- array=toFind(text, sz);
- //PRINT ARRAY//
- toPrint(array, sz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement