Advertisement
jelyslime

zad str:Printirane na poslednite simvoli na strin ot bitova

Jan 27th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void mostMet(char* uniMnoj, char* sub, int* posArr,int posSize)
  7. {
  8.     cout << endl << strlen(sub) << endl;
  9.     int tempcnt = 0;
  10.     for(int i = 10;i > 0;--i){
  11.         if (tempcnt < posSize)
  12.         {
  13.             if (sub[i] == '1')
  14.             {
  15.                 posArr[tempcnt] = i;
  16.                 tempcnt++;
  17.             }
  18.             else
  19.             {
  20.                 continue;
  21.             }
  22.         }
  23.         else
  24.         {
  25.             break;
  26.         }
  27.     }
  28.  
  29.    
  30.     cout << "The last " << posSize << " symbols are: ";
  31.     int counter2 = 0;
  32.    
  33.     for (int i = 0 ; i < tempcnt; i++)
  34.     {
  35.         int tmptocout = posArr[counter2];
  36.         cout << uniMnoj[tmptocout];
  37.         counter2++;
  38.     }
  39.  
  40.     cout << endl;
  41.  
  42.  
  43. }
  44.  
  45.  
  46.  
  47. int main()
  48. {
  49.     //zadacha stringove
  50.     // v sluchiq namirane na poslednite tri indeksa na stringa
  51.  
  52.    
  53.     char uniMnoj[] = { 'e','r','D','U','w','m','B','x','N','Z' };
  54.     char bitmask[] = { "1111001010" };
  55.    
  56.     int lastWords = 0;
  57.     cout << "Vuvedete kolko ot poslednite bukvi iskate da izpechatam " << endl;
  58.     cin >> lastWords;
  59.  
  60.     int* posArr = new int[lastWords];
  61.     mostMet(uniMnoj, bitmask, posArr, lastWords);
  62.  
  63.    
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement