[Mảng 1 Chiều Cơ Bản]. Bài 41. Xóa phần tử

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Author:
Problem source:
28Tech
Problem type
Allowed languages
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

28Tech không thích số 28 vì thế anh ta yêu cầu bạn xóa hết mọi phần tử trong mảng A[] có giá trị là 28. Sau đó in ra mảng sau khi xóa, nếu mảng không còn phần tử nào thì in ra EMPTY.


Đầu vào

Dòng 1 là N : số phần tử trong mảng

Dòng 2 là N phần tử cách nhau 1 khoảng trắng


Giới hạn

1<=N<=1000

0<=A[i]<=1000


Đầu ra

In ra mảng sau khi xóa


Ví dụ :

Input 01
5
1 28 28 3 4
Output 01
1 3 4

Comments

Please read the guidelines before commenting.



  • 0
    duy_tuan_anh  commented on Dec. 20, 2024, 9:41 a.m.

    include<bits/stdc++.h>

    using namespace std;

    int main() { int n; cin >> n; int check = 0; for(int i = 0; i < n; i++) { int x; cin >> x; if(x != 28) { cout << x << " "; check = 1; } } if(check == 0) cout << "EMPTY"; }


  • 1
    dangkhoa2836  commented on July 26, 2024, 5:15 p.m.

    // góp vui tí OOP:))

    include <iostream>

    include <vector>

    class HaiTamTech { public: HaiTamTech() : NumberOfValue(0) {}

    void setNumberOfValue() {
        std::cin >> NumberOfValue;
    }
    
    void setVecValue() {
        for (int i = 0; i < NumberOfValue; ++i) {
            int tmp;
            std::cin >> tmp;
            if (tmp != 28) vec.push_back(tmp);
        }
    }
    
    void printValues() {
        if (vec.empty()) {
            std::cout << "EMPTY";
        }
        else {
            for (int x : vec) std::cout << x << " ";
        }
    }
    

    private: int NumberOfValue; std::vector<int> vec; };

    int main() { std::iosbase::syncwith_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);

    HaiTamTech my_test;
    my_test.setNumberOfValue();
    my_test.setVecValue();
    my_test.printValues();
    
    return 0;
    

    }


  • -3
    dung_1212  commented on July 19, 2024, 3:21 p.m.

    ý tưởng đơn giản nhất là đẩy vào mảng mới, thế thôi nhá , tự hiểu


  • -3
    B22DCDT293  commented on May 26, 2024, 10:53 a.m.

    n = int(input()) a = list(map(int,input().split())) res = [] for i in a: if i != 28: res.append(i) if len(res) == 0: print('EMPTY') else: print(*res)


  • -3
    __lvhoa__  commented on May 22, 2024, 3:39 p.m.

    include <bits/stdc++.h>

    using namespace std; typedef long long ll; typedef long double lb; //const ; //Khai bao

    //Ham

    int main() { iosbase::syncwith_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(".INP", "r", stdin); //freopen(".OUT", "w", stdout); int n ; cin >> n ; vector<int> a(n); for (int i=0;i<n;i++) { cin >> a[i]; } for (int i=0;i<n;i++) { if(a[i]==28) { a.erase(a.begin()+i); i--; n--; } } if(n==0) { cout << "EMPTY"; } else { for (int c:a) cout << c << " "; } return 0; }


  • -5
    xuanthinh  commented on April 29, 2024, 11:03 a.m. edit 2

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -6
    Itachi  commented on April 29, 2024, 10:52 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.