Facebook
From Sweltering Prairie Dog, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 155
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. void dispTabV3(char tab[], int size)
  5. {
  6.     for(int i=0; i < size; i++)
  7.     {
  8.         cout << tab[i] << " ";
  9.     }
  10. }
  11. void sortowanie_alfabetyczne(char tab[], int size)
  12. {
  13.    
  14.     for(int i = 0; i < size; i++)
  15.     {
  16.         int index_literaD = i;
  17.         int index_literaM = i;
  18.         int index_litera = i;
  19.         char literaD = 123;
  20.         char literaM = 123;
  21.         char litera = 123;
  22.         for(int j = i; j < size; j++)
  23.         {
  24.             if(literaD > tab[j] && tab[j] >= 65 && tab[j] <= 90)
  25.             {
  26.                 literaD = tab[j];
  27.                 index_literaD = j;
  28.             }
  29.         }
  30.         for(int k = i; k < size; k++)
  31.         {
  32.             if(literaM > tab[k] && tab[k] >= 97 && tab[k] <= 122)
  33.             {
  34.                 literaM = tab[k];
  35.                 index_literaM = k;
  36.             }
  37.         }
  38.         if(literaM <= literaD + 32)
  39.         {
  40.             litera = literaM;
  41.             index_litera = index_literaM;
  42.         }
  43.         else
  44.         {
  45.             litera = literaD;
  46.             index_litera = index_literaD;
  47.         }
  48.         int B;
  49.         B = tab[i];
  50.         tab[index_litera] = B;
  51.         tab[i] = litera;
  52.         //swap(tab[i], tab[index_litera]);
  53.         //cout << endl << litera << endl;
  54.         //cout << endl <<literaM << " " << literaD << endl;
  55.         dispTabV3(tab ,size);
  56.     }
  57. }
  58. void dispTabV2(int tab2D[4][5], const int x, const int y)
  59. {
  60.     for(int i = 0; i < x; i++)
  61.     {
  62.         for(int j = 0; j < y; j++)
  63.         {
  64.             cout << tab2D[i][j] <<" ";
  65.         }
  66.     }
  67.     cout << endl;
  68. }
  69. void dispTab(unsigned int tab[], int size)
  70. {
  71.     for(int i=0; i < size; i++)
  72.     {
  73.         cout << tab[i] << " ";
  74.     }
  75. }
  76. int suma_cyfr(int liczba)
  77. {
  78.     int wynik = 0;
  79.     do
  80.     {
  81.         wynik = wynik + liczba%10;
  82.         liczba = liczba/10;
  83.     }
  84.     while(liczba!=0);
  85.     return wynik;
  86. }
  87.  
  88. void sort_wstawianie(unsigned int tab[], const int size)
  89. {
  90.     int key, j;
  91.     for(int i=1; i< size; i++)
  92.     {
  93.         key = tab[i];
  94.         j = i-1;
  95.        
  96.        while( j>=0 && suma_cyfr(tab[j]) < suma_cyfr(key))
  97.        {
  98.            tab[j+1] = tab[j];
  99.            j = j - 1;
  100.        }
  101.        tab[j + 1] = key;
  102.        dispTab(tab, size);
  103.     }
  104. }
  105.  
  106. void sort_babelkowe(int tab2D[4][5],const int x,const int y)
  107. {
  108.     for (int k = 0; k < 20 ; k++)
  109.     {
  110.     for(int i = 0; i < x; i++)
  111.     {
  112.         for( int j = 0; j < y; j++)
  113.         {
  114.             if( tab2D[i][j] > tab2D[i][j+1] && i != x && j != y)
  115.             {
  116.                 int B;
  117.                 B = tab2D[i][j+1];
  118.                 tab2D[i][j+1] = tab2D[i][j];
  119.                 tab2D[i][j] = B;
  120.             }
  121.             else if(tab2D[i][j]> tab2D[i+1][0])
  122.             {
  123.                 int B;
  124.                 B = tab2D[i+1][0];
  125.                 tab2D[i+1][0] = tab2D[i][j];
  126.                 tab2D[i][j] = B;
  127.                
  128.             }
  129.         }
  130.     }
  131.     }
  132.             dispTabV2(tab2D, x, y);
  133.     /*
  134.     for(int i = 0; i < x; i++)
  135.     {
  136.         for(int j = 0; j < y; j++)
  137.         {
  138.             int min = tab2D[i][j];
  139.             int minX = i;
  140.             int minY = j;
  141.             for(int w = i; w < x; w++)
  142.             {
  143.                 for(int k = j; k < y; k++)
  144.                 {
  145.                     if(tab2D[w][k] < tab2D[minX][minY])
  146.                     {
  147.                         minX = w;
  148.                         minY = k;
  149.                     }
  150.                      swap(tab2D[i][j], tab2D[minX][minY]);
  151.             cout << tab2D[minX][minY] << endl;
  152.             dispTabV2(tab2D, x, y);
  153.                 }
  154.             }
  155.         }
  156.     }*/
  157. }
  158. int main() {
  159.     int zad;
  160.     cin >> zad;
  161.    
  162.     switch(zad)
  163.     {
  164.         case 1:
  165.         {
  166.             const int size = 10;
  167.             char tab[size];
  168.             string litera;
  169.             int iteracja = 0;
  170.             bool flag = true;
  171.            
  172.             while( flag )
  173.             {
  174.                 char litera2;
  175.                 cin >> litera;
  176.                 litera2 = 0;
  177.                 if(litera.size() == 1)
  178.                 {
  179.                     litera2 = litera[0];
  180.                 }
  181.                 if((static_cast<int>(litera2) > 64 && static_cast<int>(litera2) <90) || (static_cast<int>(litera2)>96 && static_cast<int>(litera2) < 123))
  182.                 {
  183.                     tab[iteracja] = litera2;
  184.                     iteracja++;
  185.                 }
  186.                 if(iteracja == 11)
  187.                 {
  188.                     flag = false;
  189.                 }
  190.             }
  191.             sortowanie_alfabetyczne(tab, size);
  192.             break;
  193.         }
  194.         case 2:
  195.         {
  196.             const int size = 10;
  197.             unsigned int tab[size];
  198.             string liczba;
  199.             int iteracja = 0;
  200.             bool flag = true;
  201.            
  202.            
  203.             while( flag )
  204.             {
  205.                 cin >> liczba;
  206.                 bool flaga_sens = true;
  207.                 for(int i = 0; i < liczba.size(); i++)
  208.                 {
  209.                     if(static_cast<int>(liczba[i]) < 48 || static_cast<int>(liczba[i]) > 57 )
  210.                     {
  211.                         flaga_sens = false;
  212.                     }
  213.                 }
  214.                 unsigned int string_na_liczbe = 0;
  215.                 unsigned int potenga = 1;
  216.                     if(flaga_sens)
  217.                     {
  218.                         for(int i = liczba.size()-1; i >= 0; i--)
  219.                         {
  220.                            // cout << static_cast<unsigned int>(liczba[i]) << endl;
  221.                             string_na_liczbe = string_na_liczbe + (static_cast<unsigned int>(liczba[i]-48))*potenga;
  222.                             potenga = potenga * 10;
  223.                            // cout << string_na_liczbe <<" ";
  224.                         }
  225.                    
  226.                     //cout << string_na_liczbe;
  227.                     tab[iteracja] = string_na_liczbe;
  228.                     //cout << tab[iteracja] << endl;
  229.                     iteracja++;
  230.                     }
  231.                     if(iteracja == 10)
  232.                     {
  233.                         flag = false;
  234.                     }
  235.             }
  236.             //dispTab(tab, size);
  237.             sort_wstawianie(tab, size);
  238.             break;
  239.         }
  240.         case 3:
  241.         {
  242.             const int x = 4;
  243.             const int y = 5;
  244.             int tab2D[x][y];
  245.             for(int i=0; i<x; i++)
  246.             {
  247.                 for(int j=0; j<y; j++)
  248.                 {
  249.                     string liczba;
  250.                     int iteracja = 0;
  251.                     bool flag = true;
  252.                     while( flag )
  253.                     {
  254.                         cin >> liczba;
  255.                         bool flaga_sens = true;
  256.                         for(int s = 0; s < liczba.size(); s++)
  257.                         {
  258.                             if(static_cast<int>(liczba[s]) < 48 || static_cast<int>(liczba[s]) > 57 )
  259.                             {
  260.                                 flaga_sens = false;
  261.                             }
  262.                         }
  263.                         unsigned int string_na_liczbe = 0;
  264.                         unsigned int potenga = 1;
  265.                         if(flaga_sens)
  266.                         {
  267.                             for(int s = liczba.size()-1; s >= 0; s--)
  268.                             {
  269.                                 // cout << static_cast<unsigned int>(liczba[i]) << endl;
  270.                                 string_na_liczbe = string_na_liczbe + (static_cast<unsigned int>(liczba[s]-48))*potenga;
  271.                                 potenga = potenga * 10;
  272.                                 // cout << string_na_liczbe <<" ";
  273.                             }
  274.                         //cout << string_na_liczbe;
  275.                         tab2D[i][j] = string_na_liczbe;
  276.                         //cout << tab[iteracja] << endl;
  277.                         iteracja++;
  278.                         }
  279.                         if(iteracja == 1)
  280.                         {
  281.                             flag = false;
  282.                         }
  283.                     }
  284.                 }
  285.             }
  286.             sort_babelkowe(tab2D, x, y);
  287.             break;
  288.             }
  289.         }
  290.         return 0;
  291. }