Advertisement
jibha

Untitled

Jan 24th, 2022
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int countStudents(vector<int>& students, vector<int>& sandwiches) {
  4.  
  5. // queue<int> stu;
  6. stack<int> san;
  7.  
  8. // for(int i:students){
  9. // stu.push(i);
  10. // }
  11. for(int i:sandwiches){
  12. san.push(i);
  13. }
  14.  
  15.  
  16. int changes=1;
  17. while(changes==1){
  18. changes=0;
  19. for(int i=0;i<students.size();i++){
  20. if(san.size()==0){
  21. break;
  22. }
  23. if(san.top()==students[i]){
  24. cout<<san.top()<<' '<<students[i]<<endl;
  25. students[i]=-1;
  26. changes=1;
  27. san.pop();
  28. }
  29. }
  30. }
  31. int ans=0;
  32. for(int i:students){
  33. // cout<<i<<' ';
  34. if(i!=-1){
  35. ans++;
  36. }
  37. }
  38.  
  39. cout<<endl;
  40.  
  41. return ans;
  42. }
  43. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement