Advertisement
193030

NBU 2019 10. Obuvki, vadi samo pyrviq veren input i e greshn

Apr 2nd, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.29 KB | None | 0 0
  1.  
  2. // Example program
  3. #include <iostream>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.     int first, second;
  9.     string input;
  10.     int masivNoseniNomera[10] = {};
  11.    int masivNalichniNomera[10] = {};
  12.     int noseniNomeraCounter = 1;
  13.     int nalichniNomeraCounter = 1;
  14.     string newString;
  15.    int arrayCounter [] = {};
  16.    int whileTimes = 0;
  17.  
  18.     long sstoi(const char *s) // custom stoi function
  19. {
  20.     long i;
  21.     i = 0;
  22.     while(*s >= '0' && *s <= '9')
  23.     {
  24.         i = i * 10 + (*s - '0');
  25.         s++;
  26.     }
  27.     return i;
  28. }
  29. int counter =0;
  30. int arrayOutput[10] = {};
  31. int whileCounter = 0;
  32. int main()
  33. {
  34.     for(int i=0; i<10; i++)
  35.     {
  36.  
  37.         arrayCounter[i] = 0;
  38.         arrayOutput[i] = 0;
  39.     }
  40.  
  41.    stringstream sstream;
  42.    int k =0;
  43.    cin >> k;
  44.    cin.ignore();
  45.  
  46.    while(k--)
  47.    {
  48.       // cout << "Loop" << endl;
  49.     if(whileTimes>0)
  50.     {
  51.         cin.ignore();
  52.     }
  53.    getline(cin, input);
  54.     sstream.str(input);
  55.     sstream >> newString;
  56.     int firstNumber = sstoi(newString.c_str());
  57.   //   masivNoseniNomera[firstNumber] = {};
  58.     sstream >> newString;
  59.     int secondNumber = sstoi(newString.c_str());
  60.   //   masivNalichniNomera[secondNumber] = {};
  61.     sstream.str("");
  62.     sstream.clear(); // izchistva greshki
  63.  
  64.    getline(cin, input);
  65.    sstream.str(input);
  66.   sstream >> newString;
  67.    masivNoseniNomera[0] = sstoi(newString.c_str());
  68.    while(sstream.eof()!=1)
  69.    {
  70.         sstream >> newString;
  71.       //  sstream.clear();
  72.         masivNoseniNomera[noseniNomeraCounter] = sstoi(newString.c_str());
  73.         noseniNomeraCounter++;
  74.  
  75.  
  76.    }
  77.     sstream.str("");
  78.     sstream.clear(); // izchistva greshki
  79.  
  80.  
  81.  
  82.     //
  83.     getline(cin, input);
  84.     sstream.str(input);
  85.     sstream >> newString;
  86.     masivNalichniNomera[0] = sstoi(newString.c_str());
  87.     while(sstream.eof()!=1)
  88.     {
  89.         sstream >> newString;
  90.       //  sstream.clear();
  91.         masivNalichniNomera[nalichniNomeraCounter] = sstoi(newString.c_str());
  92.         nalichniNomeraCounter++;
  93.  
  94.  
  95.     }
  96.     sstream.str("");
  97.     sstream.clear(); // izchistva greshki
  98.  
  99.  
  100.  
  101.  
  102.  /* cout << "The first number is: " << firstNumber << " and the second number is: " << secondNumber << endl;
  103.    for(int i =0; i<noseniNomeraCounter; i++)
  104.     {
  105.     cout << masivNoseniNomera[i] << endl;
  106.     }
  107. }*/
  108.         for(int i =0; i<noseniNomeraCounter; i++)
  109.         {
  110.             int segashenNosenNomer = masivNoseniNomera[i];
  111.             for(int j =0; j<nalichniNomeraCounter;j++)
  112.             {
  113.                 int segashenNalicherNomer = masivNalichniNomera[j];
  114.                 if((segashenNosenNomer<=segashenNalicherNomer) && (segashenNalicherNomer !=0))
  115.                 {
  116.                     counter++;
  117.                     masivNalichniNomera [j] = 0;
  118.                     break;
  119.                 }
  120.             }
  121.  
  122.         }
  123.        // cout << "PRINTVAM COUNTER" << counter << endl;
  124.         arrayOutput[whileCounter]= counter;
  125.         whileCounter++;
  126.     for(int i =0; i<=9; i++)
  127.     {
  128.       masivNoseniNomera[i] =0;
  129.     }
  130.     for(int i =0; i<=9; i++)
  131.     {
  132.  
  133.         masivNalichniNomera[i] =0;
  134.     }
  135.  
  136.  
  137.     noseniNomeraCounter = 0;
  138.     nalichniNomeraCounter =0;
  139.     counter = 0;
  140.  
  141. }
  142.  
  143.  
  144. for(int i =0; i<whileCounter; i++)
  145. {
  146.     cout << arrayOutput[i]<< endl;
  147. }
  148.  
  149.  
  150.  
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement