//////当队伍只剩下一种偏好 且 不等于栈顶时-> 终止
#include<deque>
#include<stack>
bool isallsame(deque<int>d){
int same=d[0];
for(deque<int>::iterator it=d.begin()+1;it!=d.end();it++){
if((*it)!=same){
return 0;
}
}
return 1;
}
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param students int整型vector
* @param sandwiches int整型vector
* @return int整型
*/
int countStudents(vector<int>& students, vector<int>& sandwiches) {
// write code here
deque<int>d;
stack<int>s;
for(int i=0;i<students.size();i++){
d.push_back(students[i]);
}
for(int i=sandwiches.size()-1;i>=0;i--){
s.push(sandwiches[i]);
}
while(!d.empty()){
if(isallsame(d)&&d.front()!=s.top()){
return d.size();
}
if(d.front()==s.top()){
d.pop_front();
s.pop();
}
else if(d.front()!=s.top()){
d.push_back(d.front());
d.pop_front();
}
}
return d.size();
}
};