只用看它们的next指针是否有重合即可

Sharing

https://www.nowcoder.com/practice/2577bea713cf4eed874afccff1928113

#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
    int start1, start2, n;
    while (cin >> start1 >> start2 >> n) {
        unordered_set<int> set;
        while (n--) {
            int cur, next;
            char c;
            cin >> cur >> c >> next;
            if (set.count(next) == 0) set.insert(next);
            else {
                cout << next << endl;
            }
        }
    }
    return 0;
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务