Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <string.h>
- using namespace std;
- int main(int argc, char** argv) {
- cout << "Input string" << endl;
- char str[255];
- cin.getline(str,255);
- int length = strlen(str);
- int arr[length];
- for(int i=0;i<length;i++)
- {
- if (isdigit((unsigned char)str[i]))
- {
- arr[i] = str[i] - '\0';
- arr[i]-=48;
- }
- }
- for (int i = 0; i < length; i++) {
- for (int j = 0; j < length-1; j++) {
- if (arr[j] < arr[j + 1]) {
- int temp = arr[j]; // ñîçäàëè äîïîëíèòåëüíóþ ïåðåìåííóþ
- arr[j] = arr[j + 1]; // ìåíÿåì ìåñòàìè
- arr[j + 1] = temp; // çíà÷åíèÿ ýëåìåíòîâ
- }
- }
- }
- for (int i = 0; i < length; i++) {
- cout << arr[i] << " "; // âûâîäèì ýëåìåíòû ìàññèâà
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement