codeforces B. Restore the Permutation by Merger

codeforces B. Restore the Permutation by Merger_第1张图片

题目

题意:

对于每一个序列,我们将首个出现的数字截取写来,然后形成新得序列,请输出序列。

思路:

用一个数组记录出现过的字母,然后未出现的直接输出就行了,然后不断更新数组就行了。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
int xxxxxxxxx = 1;
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
inline void debug(ll x) {cout << xxxxxxxxx++ << " " << x << endl;}
inline void debugs(string s) {cout << s << endl;}
const int maxn = 60;
int cnt[maxn] = {0};
int main() {
    int t; read(t); while (t--) {
        memset(cnt, 0, sizeof(cnt));
        vector<int> v;
        int n; read(n); for (int i = 0; i < 2 * n; i++) {
            int x; read(x); if (cnt[x] == 0) v.push_back(x), cnt[x] = 1;
        }
        for (int i = 0; i < v.size(); i++) {
            printf("%d ", v[i]);
        }
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(codeforces)