Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #include <iostream>
  5. #pragma hdrstop
  6. #include <string.h>
  7.  
  8. #include "Unit1.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma resource "*.dfm"
  12. TForm1 *Form1;
  13. //---------------------------------------------------------------------------
  14. __fastcall TForm1::TForm1(TComponent* Owner)
  15. : TForm(Owner)
  16. {
  17. }
  18. //---------------------------------------------------------------------------
  19. void __fastcall TForm1::Button1Click(TObject *Sender)
  20. {
  21. int sm = ComboBox1 -> ItemIndex;
  22. String s = ComboBox1 -> Items -> Strings[sm];
  23. char * z = s.c_str();
  24. int n = 0;
  25. char * num = strtok (z, " ");
  26. while (num)
  27. {
  28. n++;
  29. num = strtok (NULL, " ");
  30. }
  31. int * A = new int [n];
  32. num = strtok (z, " ");
  33. for (int i = 0; i<n; i++)
  34. {
  35. A[i]= atoi(num);
  36. num = strtok (NULL, " ");
  37. }
  38. for (int i = 0; i<n-1; i++)
  39. {
  40. for(int j = 0; j<n-i-1; j++)
  41. {
  42. if (A[j] > A[j+1])
  43. {
  44. int temp = A[j];
  45. A[j] = A [j+1];
  46. A [j+1] = temp;
  47. }
  48. }
  49. }
  50. String result = String (A[0]);
  51. for (int i = 1; i<n; i++)
  52. {
  53. result += " " + String (A[i]);
  54. }
  55. ComboBox1 -> Items -> Add(result);
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TForm1::Button2Click(TObject *Sender)
  59. {
  60. ComboBox1 -> Items -> Add(ComboBox1 -> Text);
  61. ComboBox1 -> Text = "";
  62. }
  63. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement