Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char** argv) {
  8. cout << "Input string" << endl;
  9. char str[255];
  10. cin.getline(str,255);
  11. int length = strlen(str);
  12. int arr[length];
  13. for(int i=0;i<length;i++)
  14. {
  15. if (isdigit((unsigned char)str[i]))
  16. {
  17. arr[i] = str[i] - '\0';
  18. arr[i]-=48;
  19. }
  20. }
  21.  
  22. for (int i = 0; i < length; i++) {
  23. for (int j = 0; j < length-1; j++) {
  24. if (arr[j] < arr[j + 1]) {
  25. int temp = arr[j]; // ñîçäàëè äîïîëíèòåëüíóþ ïåðåìåííóþ
  26. arr[j] = arr[j + 1]; // ìåíÿåì ìåñòàìè
  27. arr[j + 1] = temp; // çíà÷åíèÿ ýëåìåíòîâ
  28. }
  29. }
  30. }
  31.  
  32. for (int i = 0; i < length; i++) {
  33. cout << arr[i] << " "; // âûâîäèì ýëåìåíòû ìàññèâà
  34. }
  35.  
  36. system("pause");
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement