Facebook Interview Question: Puzzle problem was given. ... | Glassdoor

Interview Question

Software Engineer Intern Interview(Student Candidate) Pittsburgh, PA

Puzzle problem was given.

Answer

Interview Answer

1 Answer

0

Roman Literals to Numerals

#include
#include

int convertRomanToNum(std::string Rinput)
{
    std::map Rmap;
    std::map::iterator Rmap_Iter;
    Rmap.insert(std::pair('I',1));
    Rmap.insert(std::pair('V',5));
    Rmap.insert(std::pair('X',10));

    char Prev = '\0';
    int result = 0;
    int n = 0;

    for(int i=0; isecond) -2) : (Rmap_Iter->second));
        Prev = Rinput[i];
    }

    return result;

}

int main()
{
    int result = 0;
    result = convertRomanToNum("VIII");
    std::cout << result << std::endl;
    result = convertRomanToNum("XXVII");
    std::cout << result << std::endl;

Anonymous on Nov 10, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.