我在竞争性编程中遇到了初学者概念的问题
打印中的额外空间可能会导致错误的答案判断
我想迭代像地图或集合这样的容器,但最后一个值不应该有空格
#include <iostream>
#include <set>
using namespace std;
int main()
{
set<int> st = {1,2,3};
for(auto x : st){
cout<<x<<" ";
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
set<int> st = {1,2,3};
for(auto x = st.begin(); st!=end();x++){
if(x!=st.end()-2) cout<<x<<" ";
else cout<<x;
}
Run Code Online (Sandbox Code Playgroud)