mostafaabdelaal_03's blog

By mostafaabdelaal_03, history, 9 months 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

»
9 months ago, # |
  Vote: I like it -6 Vote: I do not like it

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

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
9 months ago, # |
  Vote: I like it +29 Vote: I do not like it

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

  • »
    »
    9 months ago, # ^ |
      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());

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I think using maps is overcomplicating