Home c++ Coupling dictionary Map

Coupling dictionary Map

Author

Date

Category

I already wrote a question on this topic, but a new problem appeared.
It seems I do something wrong. This program is a task of a workshop. What I wrote works correctly, the dictionary turns over.
Here is the code:

# include & lt; iostream & gt;
# INCLUDE & LT; String & GT;
# INCLUDE & LT; MAP & GT;
Using Namespace STD;
Map & LT; String, String & GT; BuildReversedMap (Const Map & Lt; String, String & GT; & amp; m) {
  // ...
  Map & LT; String, String & GT; Newmap;
  For (Const Auto & Amp; [Key, Value]: M)
  {
    NEWMAP [KEY] = VALUE;
  }
  Return newmap;
}
Map & LT; String, String & GT; G = {{"Cat", "Felis Catus"}, {"Dog", "CANIS LUPUS"}};
INT MAIN ()
{
  For (Const Auto & Amp; [Key1, Value1]: BuildReversedMap (G))
    COUT & LT; & LT; "{" S & LT; & lt; Value1 & lt; & lt; "," & lt; & lt; key1 & lt; & lt; "}," s;
  Return 0;
}

But in response I get it:

Task passed 2/4 checks

Possible problems:

  • Your function incorrectly draws the dictionary

I confuse something or isn’t it in the dictionary?


Answer 1, Authority 100%

# include & lt; iostream & gt;
# INCLUDE & LT; String & GT;
# INCLUDE & LT; MAP & GT;
Using Namespace STD;
Map & LT; String, String & GT; BuildReversedMap (Const Map & Lt; String, String & GT; & amp; m) {
  // ...
  Map & LT; String, String & GT; Newmap;
  For (Const Auto & Amp; [Key, Value]: M)
  {
    Newmap [Value] = Key;
  }
  Return newmap;
}
Map & LT; String, String & GT; G = {{"Cat", "Felis Catus"}, {"Dog", "CANIS LUPUS"}};
INT MAIN ()
{
  For (Const Auto & Amp; [Key1, Value1]: BuildReversedMap (G))
    cout & lt; & lt; "{" s & lt; & lt; key1 & lt; & lt; "," & lt; & lt; value1 & lt; & lt; "}," s;
  Return 0;
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions