When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

ScienceGuy's blog

By ScienceGuy, history, 7 years ago, In English

http://codeforces.com/gym/101306/problem/D Here is an easy problem, but I get WA on test 6. Can you please tell me how to solve it or what I'm doing wrong? I guess that the "Martian to English" alphabet must be figured out from the test case examples (they include all of the 26 letters, uppercase and lowercase). So I put them in a 'map' and then print the answers, which is correct for the examples, but not for the 6th test. Here is my code: https://pastebin.com/sCZJnLZB

  • Vote: I like it
  • 0
  • Vote: I do not like it

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

If you look closely, there is 51 (distinct)mapping in the samples, so you have to map the last one on your own.

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

    Thanks.

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

      I was going to say this but was a bit too late.

      I appreciate your thinking on using a map.

      A minor suggestion. Code would be a bit more readable if you wrote the dictionary like this.

      string martian   
       ="CARScarsIuVEJxTXsUvOHhngyZKfAYmaqolMNtGQibwdjPrCpekFWzLaySBaPybRMgzYMynY";
      string meaning     
        ="UnilEPFLvpVZzBNtLSCubWmaocIYneAPqxDshRkMGgJfHrFUQTjXOwdPolyProgisawesome";
      
      map <char, char> dictionary;
      /* next for loop creates the Martian-To-English alphabet */
      for(unsigned int i=0; i < martian.length(); i++)
          dictionary[martian[i]]=  meaning[i];

      Remember comments are good. But, self-documenting code is better. This is because as time goes on, code often evolves and changes, but comments don't. Rather than put in a comment saying n is the number of words, name n as number of words.

      Also, another thing is that because you're using an STL string, you can use .length() ... it works in O(1) time. However, if this was a C-string, then you shouldn't have used strlen everytime because it makes the complexity O(n^2) instead of O(n). It's another minor thing that worked to your advantage here, but remember the complexities of the functions that you use.

      Otherwise good work. You just missed out on the fact that there were 51 alphabets and not 52.