abdelaal_03's blog

By abdelaal_03, history, 2 years ago, In English
I get The idea of Problem D Today But I was getting WA and I did not know where is the wrong.. After the contest I discovered that my map donot do sorting to vector of string in it ...
why ???
map<char, vector<string>>mp;
for(auto i:mp){
    sort(i.second.begin(), i.second.end());
}

this is the test that my friend give me after contest:

1

1

D

9H 4H

  • Vote: I like it
  • -5
  • Vote: I do not like it

| Write comment?
»
2 years ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

you should have done sort(mp[i.first].begin(), mp[i.first].end());

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by abdelaal_03 (previous revision, new revision, compare).

»
2 years ago, hide # |
 
Vote: I like it +29 Vote: I do not like it

for (auto &i : mp), you just make a copy every time

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yes it's the reference trick.

    Or you can use iterators: for (auto it=mp.begin();it!=mp.end();it++) sort(it->second.begin(),it->second.end());