小苯的文章浏览【Python实现和C++】

小苯的文章浏览【Python实现和C++】

编码文章call10242025-07-08 13:47:484A+A-
n = int(input())
seen = set()
order = []

for _ in range(n):
    user = input().strip()
    if user not in seen:
        seen.add(user)
        order.append(user)

for u in order:
    print(u)


#include <iostream>
#include <unordered_set>
#include <vector>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);  // 禁用同步,加速输入输出
    cin.tie(nullptr);             // 解除cin与cout的绑定
    
    int n;
    cin >> n;
    cin.ignore();  // 忽略第一行的换行符
    
    unordered_set<string> seen;
    vector<string> order;
    
    string line;
    for (int i = 0; i < n; ++i) {
        getline(cin, line);
        if (seen.find(line) == seen.end()) {  // 如果未出现过
            seen.insert(line);
            order.push_back(line);
        }
    }
    
    // 输出结果
    for (const auto& user : order) {
        cout << user << '\n';
    }
    
    return 0;
}
点击这里复制本文地址 以上内容由文彬编程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

文彬编程网 © All Rights Reserved.  蜀ICP备2024111239号-4