Guest User

c++ prog

a guest
Feb 14th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <vector>
  4. #include <locale>
  5.  
  6. using namespace std;
  7.  
  8.     const int N = 5;
  9.  
  10.     vector<array<char, N>> Cserel(char * szam, int i1, int i2){
  11.         char ch;
  12.         ch = szam[i1];
  13.         szam[i1] = szam[i2];
  14.         szam[i2] = ch;
  15.         Cserel = szam;
  16.     }
  17.  
  18. vector<array<char, N>> Keres(char * szam)
  19. {
  20. a:
  21.     int indA, indB, meddig, i, j;
  22.  
  23.     indA = -1;
  24.     i = N - 1;
  25.     while (i > 0 && indA == -1)
  26.     {
  27.         if (szam[i - 1] < szam[i])
  28.         {
  29.             indA = i - 1;
  30.         }
  31.         i = i - 1;
  32.     }
  33.     if (indA = -1)
  34.     {
  35.         goto a;
  36.     }
  37.     indB = indA + 1;
  38.     for (j = indA + 2; j < N - 1; j++)
  39.     {
  40.         if (szam[j] > szam[indA] && szam[j] < szam[indB])
  41.         {
  42.             indB = j;
  43.         }
  44.     }
  45.     szam = Cserel(szam, indA, indB);
  46.     for (meddig = N - 1; meddig < N; meddig--)
  47.     {
  48.         for (j = indA + 1; j < meddig - 1; j++)
  49.         {
  50.             if (szam[j] > szam[j + 1])
  51.             {
  52.                 Cserel(szam,j,j+1)
  53.             }
  54.         }
  55.     }
  56.  
  57.     Keres = szam;
  58. }
  59.  
  60. int main()
  61. {
  62.     char * szam;
  63.     szam[0] = '5';
  64.     szam[1] = '2';
  65.     szam[2] = '6';
  66.     szam[3] = '3';
  67.     szam[4] = '1';
  68.     cout << szam;
  69.     cout << Keres(szam);
  70.         system("pause");
  71. }
Advertisement
Add Comment
Please, Sign In to add comment