奇安信0816笔试第一题0第二题0.8
第一题不再多说,如果说题目有问题,我相信这么大的公司会出来解释的,如果不解释,那也没办法,谁叫咱是求职者呢,对方有最终解释权。
第二题80%,不知道哪儿错了,求大佬讲解,我自己试过在原来位置恢复和在当前位置之后恢复原来的字符串两种,比如:hello undo world redo 是输出hello world 呢 还是 输出 world hello 呢?两种我都试过,都是80%,我最后交的第一种。下面贴上代码:
#include<iostream>
#include<vector>
#include<stack>
#include<functional>
#include<string>
#include<sstream> //方便读入分割字符串,看不懂不用管
using namespace std;
int main()
{
cout.sync_with_stdio(false); //加速读取的操作与stringstream 同用
string s;
while (getline(cin, s))
{
vector<string> res;
stringstream line(s);
stack<pair<string, int>> pres;
string ss;
while (line >> ss)
{
if (ss == "undo")
{
if (res.size()>0)
{
int pos = (int)res.size() - 1;
string temp = res[pos];
res.pop_back();
pres.push({ temp, pos });
}
}
else if (ss == "redo")
{
if (pres.size()>0)
{
auto t = pres.top();
pres.pop();
int pos = t.second;
string temp = t.first;
res.insert(res.begin() + pos, temp);
}
}
else
{
res.push_back(ss);
}
}
string ans = "";
for (int i = 0; i<res.size(); i++)
{
if (i != res.size() - 1)
{
ans += res[i] + " ";
}
else
{
ans += res[i];
}
}
cout << ans;
}
return 0;
}
海康威视公司福利 1117人发布
查看1道真题和解析