#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
/*
1.系统中有最近打开文件的记录,先用整数表示打开的文件名,且只显示最近3个打开的文件,输出文件序列。
eg:
输入:1 输出:1
输入:2 输出:2,1
输入:3 输出:3,2,1
输入:4 输出:4,3,2
输入:1 输出:1,4,3
输入:4 输出:1,4,3 //注:没有改变顺序
输入:3 输出:1,4,3
*/
int find(int* a, int num, int t){
for(int i =0; i<t; i++){
if(a[i] == num)
return 1;
}
return 0;
}
int main(){
int num, a[3];
memset(a, -1, sizeof(a));
int t = 0; //数字数量
int k = 0; //目录中是否存在
while(1){
cout << "输入:";
cin >> num;
//查找是否存在
if(t != 0)
k = find(a, num, t);
//最近目录中不存在num
if(k == 0){
if(t < 3)t++;
for(int i=t-1; i>0; i--){
a[i] = a[i-1];
}
a[0] = num;
}
//输出目录
cout << "输出:" ;
for(int i=0; i<t; i++){
cout << a[i] << ' ' ;
}
cout << endl;
}
return 0;
}
2014北理上机-最近目录文件
最新推荐文章于 2021-07-24 22:46:41 发布