Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ======================
- [ ___T_ ]
- [ | 6=6 | =>HI :-)]
- [ |__o__| ]
- [ >===]__o[===< ]
- [ [o__] ]
- [ .". ]
- [ |_| ]
- [ ]
- ======================
- */
- #include<bits/stdc++.h>
- using namespace std;
- using lli = int64_t;
- //print unique element if order doesn't matter
- void print_unique_unordered(int input[],int n){
- unordered_set<int> unique;
- for(int i = 0; i < n; i++){
- unique.insert(input[i]);
- }
- for(auto i : unique){
- cout << i << " ";
- }
- }
- //ordered
- void print_unique_ordered(int input[],int n){
- set<int> unique;
- for(int i = 0; i < n; i++){
- unique.insert(input[i]);
- }
- for(auto i : unique){
- cout << i << " ";
- }
- }
- void print_sum_of_unique_element(int input[],int n){
- unordered_set<int> unique;
- int sum = 0;
- for(int i = 0; i < n; i++){
- int size = (int) unique.size();
- unique.insert(input[i]);
- if(size != (int) unique.size()){
- sum += input[i];
- }
- }
- cout << sum << "\n";
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- int input[n];
- for(int i = 0; i < n; i++){
- cin >> input[i];
- }
- print_unique_ordered(input,n);
- print_unique_unordered(input,n);
- print_sum_of_unique_element(input,n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement