978A - Remove Duplicates - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

a=int(input())
b=[int(i) for i in input().split()]
c=[]
d=a-1
for i in range(a):
    if b.count(b[d])==1:
        c=c+[b[d]]
    if b.count(b[d])!=1 and c.count(b[d])==0:
        c=c+[b[d]]
    d=d-1
c=c[::-1]
print(len(c))
print(*c)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int was[1005];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n+3];
    vector <int> v;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=n;i>=1;i--){
        if(was[a[i]]==0){
            v.push_back(a[i]);
            was[a[i]]++;
        }
    }
    reverse(v.begin(),v.end());
    cout << v.size() << "\n";
    for(int i=0;i<v.size();i++){
        cout << v[i] << " ";
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

489A - SwapSort
932A - Palindromic Supersequence
433A - Kitahara Haruki's Gift
672A - Summer Camp
1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum
1659A - Red Versus Blue
1659B - Bit Flipping
1480B - The Great Hero
1519B - The Cake Is a Lie
1659C - Line Empire
515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks
1251B - Binary Palindromes
768B - Code For 1