本文主要是介绍1401:机器翻译,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
分析:模拟题,用vector模拟队列实现
指向queue队首的l指针,指向queue队尾的r指针(用push_back()代替也一样)
指针更新情况为:
- 搜索有单词,不做处理
- 搜索无单词,判断内存长度,若足够添加单词并计数,若不足则删除单词再添加单词并计数
#include<iostream>
#include<vector>
using namespace std;int main() {int m, n, t;cin >> m >> n;vector<int> mem(n + 5);int l = 0, r = 0, cnt = 0;for (int i = 0; i < n; i++) {cin >> t;if (i == 0) {cnt++;mem[r] = t;continue;}int flag = 0;for (int j = l; j <= r; j++) {if (t == mem[j]) {flag = 1;break;}}if (flag) continue;else {if (r - l + 1 >= m) l++;mem[++r] = t;cnt++;}}cout << cnt;return 0;
}
这篇关于1401:机器翻译的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!