Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10.31 答案不严谨 #104

Open
CCJ623 opened this issue Nov 12, 2023 · 0 comments
Open

10.31 答案不严谨 #104

CCJ623 opened this issue Nov 12, 2023 · 0 comments

Comments

@CCJ623
Copy link

CCJ623 commented Nov 12, 2023

unique_copy 只能去除相邻的重复元素,如果在输入流中的序列不是有序的,那么unique_copy并不能完全去掉所有重复元素,所以在使用 unique_copy 之前要先排序

下面是我的代码,先全部拷贝到vector中,进行排序,再用unique_copy 拷贝到输出迭代器中

istream_iterator<int> in_iter(cin), eof;
ostream_iterator<int> out_iter(cout, " ");
vector<int> v;
copy(in_iter, eof, back_inserter(v));
sort(v.begin(), v.end());
unique_copy(v.cbegin(), v.cend(), out_iter);
cout << endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant