class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param students int整型vector
* @param sandwiches int整型vector
* @return int整型
*/
int countStudents(vector<int>& students, vector<int>& sandwiches) {
int n=students.size();
queue<int>student,sandwich;
for(int i=0;i<n;i++){
student.push(students[i]);
sandwich.push(sandwiches[i]);
}
//连续无法匹配的次数如果大于当前队伍中的人数,说明剩余学生都不满足;
int failedmatch=0;
while(!student.empty() && failedmatch < student.size()){
if(student.front()==sandwich.front()){
student.pop();
sandwich.pop();
failedmatch=0;
}else{
student.push(student.front());
student.pop();
failedmatch++;
}
}
return student.size();
}
};