I'm having a problem with a beginner concept
in competitive programming extra space in print may cause wrong answer judgment
I want to iterate through a container like map or set but last value should not have a space
#include <iostream>
#include <set>
using namespace std;
int main()
{
set<int> st = {1,2,3};
for(auto x : st){
cout<<x<<" ";
}
return 0;
}
why can't I do this
set<int> st = {1,2,3};
for(auto x = st.begin(); st!=end();x++){
if(x!=st.end()-2) cout<<x<<" ";
else cout<<x;
}