Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. void sort(int arr[], int a){
  8. for (int i = 0;i < a; i++){
  9. for (int j = 1; j <= a - 1; j++){
  10. if (arr[j] < arr[j-1])
  11. swap(arr[j], arr[j-1]);
  12. }
  13. }
  14. }
  15.  
  16. void SortNumbers(string &src){
  17. string temp = "", new_str = "";
  18. int t = src.size();
  19. int k = 0;
  20. int temp_ = 0;
  21. int arr[15];
  22. for(int i = 0; i < t;i++){
  23. if(src[i] != ' '){
  24. temp += src[i];
  25. }
  26. else
  27. {
  28. if(atoi(temp.c_str()) != 0){
  29. temp_ = atoi(temp.c_str());
  30. arr[k] = temp_;
  31. temp = "";
  32. k++;
  33.  
  34. }
  35. else
  36. temp = "";
  37.  
  38. }
  39. }
  40. temp = "";
  41. sort(arr, k);
  42. int c = 0;
  43. for(int i = 0; i < t; i++){
  44. if(src[i] != ' '){
  45. temp += src[i];
  46. }
  47. else
  48. {
  49. if(atoi(temp.c_str()) != 0){
  50. new_str += to_string(arr[c]);
  51. c++;
  52. new_str += " ";
  53. temp = "";
  54.  
  55. }
  56. else{
  57. new_str += temp;
  58. new_str += " ";
  59. temp = "";
  60. }
  61. }
  62. }
  63. cout << new_str << endl;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement