Advertisement
193030

NBU 2019 09. Obuvki samo test #0

Apr 3rd, 2020
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5. #include <vector>
  6. #include <stdio.h>
  7.  
  8.  
  9. using namespace std;
  10. string input;
  11. stringstream stream;
  12. string newString;
  13. vector <int> noseniNomera(0);
  14. vector <int> nalichniNomera(0);
  15. vector <int> resultV(0);
  16. int firstNumber, secondNumber = 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.  
  30.  
  31. int solve()
  32. {
  33.     int counter = 0;
  34. //    for(int i =0; i<noseniNomera.size();i++)
  35.   //  {
  36.     int l =0;
  37.     int sizeNalichniNomera= nalichniNomera.size();
  38.       for(int j =0; j<nalichniNomera.size();j++)
  39.        {
  40.            if(l==sizeNalichniNomera)
  41.         {
  42.             break;
  43.         }
  44.         int currNosenNomer = noseniNomera[l];
  45.         int currNalichenNomer = nalichniNomera[j];
  46.         //if((noseniNomera[i]<=nalichniNomera[j]) && (nalichniNomera[j]!=0))
  47.         if((currNosenNomer<=currNalichenNomer) && (currNalichenNomer!=0))
  48.         {
  49.         nalichniNomera[j]=0;
  50.         l++;
  51.         counter++;
  52.        // break;
  53.         }
  54.  
  55.  
  56.  
  57.        }
  58.  
  59.  
  60.     return counter;
  61.  
  62.  
  63. }
  64. int main()
  65. {
  66.    //ios_base::sync_with_stdio(false);
  67.   int k =0;
  68.   cin >> k;
  69.   cin.ignore();
  70.   int loopCounter = 0;
  71.   while(k--)
  72.   {
  73.       getline(cin,input);
  74.       stream.str(input);
  75.       stream >> newString;
  76.       firstNumber = sstoi(newString.c_str());
  77.       stream >> newString;
  78.       secondNumber = sstoi(newString.c_str());
  79.       stream.clear();
  80.       input = "";
  81.  
  82.  
  83.       getline(cin, input);
  84.       stream.str(input);
  85.       int newNum =0;
  86.        while(stream>>newNum)
  87.         {
  88.        //     int currentNum =  sstoi(newString.c_str());
  89.             int currentNum = newNum;
  90.             noseniNomera.push_back(currentNum);
  91.         }
  92.        // cin.ignore();
  93.         getline(cin, input);
  94.         stream.str(input);
  95.         stream.clear();
  96.         input = "";
  97.  
  98.  
  99.        while(stream>>newString)
  100.         {
  101.             int currentNum =  sstoi(newString.c_str());
  102.             nalichniNomera.push_back(currentNum);
  103.         }
  104.         stream.clear();
  105.         int result = solve();
  106.         //resultV.push_back(result);
  107.        // resultV[loopCounter] = result;
  108.         loopCounter ++;
  109.         //cout << "The result is: " <<result << endl;
  110.         cout << result << endl;
  111.         noseniNomera.clear();
  112.         nalichniNomera.clear();
  113.         input = "";
  114.  
  115.  
  116.        // cout << "the first number is:  " << firstNumber << " and the second number is: " << secondNumber << endl;
  117.   }
  118.  /* for(int i =0; i<resultV.size();i++)
  119.   //for(int i =0; i<loopCounter; i++)
  120.   {
  121.       cout << resultV[i] << endl;
  122.      //   printf("%d \n", resultV[i]);
  123.   }
  124.  */
  125.   /*
  126.   for(int i =0; i<noseniNomera.size(); i++)
  127.   {
  128.       cout << "First string" << noseniNomera[i] << endl;
  129.  
  130.   }
  131.    for(int i =0; i<noseniNomera.size(); i++)
  132.    {
  133.         cout << "Second string" << nalichniNomera[i]<< endl;
  134.  
  135.     }
  136.     */
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement