参考:http://blog.csdn.net/chenhq1991/article/details/7865285
题目本身并不难,就是将一个整数序列输入时先去掉相邻重复的,然后再从后开始记录最后(从后开始的话就是最早的)一个已存在的整数,后面相同的则不再记录,最后输出即可。但是不知道为什么自己打出来的始终是超时......
原版:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <list>
using namespace std;
int main()
{
int C, N;
while (cin >> C >> N)
{
list<int> s;
int cert = 0, temp = 0;
for (int i = 0; i < N; i++)
{
cin >> temp;
if (temp == cert)
{
continue;
}
else
{
cert = temp;
s.push_back(cert);
}
}
bool* existed = new bool[C+1];
memset(existed, false, sizeof(existed));
list<int> ansR;
for (int i = s.size() - 1; i >= 0; i--)
{
int temp = s.back();
s.pop_back();
if(!existed[temp])
{
existed[temp] = true;
ansR.push_back(temp);
}
}
while (!ansR.empty())
{
if (ansR.size() == 1)
{
cout << ansR.back() << endl;
}
else cout << ansR.back() << " ";
ansR.pop_back();
}
}
}