title: Roman to Integer - But using a "different" Roman number system
body: <p>I had an interview in which I did terribly. So, now I'm trying to find the solution to the question. Here is the interview question: </p>
  
  <p>"We have the following mapping:<br>
  M: 1000, D: 500, C: 100, L: 50, X: 10, V: 5, I: 1.</p>
  
  <p>And we have the following rules:</p>
  
  <ol>
  <li><p>Each letter maps to a positive integer value</p></li>
  <li><p>You add the values together, except...</p></li>
  <li><p>...when a value (or runs of the same values) is followed by a greater value, you subtract the total of that run of values.</p></li>
  </ol>
  
  <p>Examples:</p>
  
  <p>IIX -> 8</p>
  
  <p>MCCMIIX -> 1808</p>
  
  <p>We are given this Java method: <code>int valueOfRoman(char roman)</code>.
  We have implement the Java method: <code>int romanToInt(String s)</code>"</p>
  
  <p>I know it is not a proper roman number system, but that is the actual question.</p>
  
  <p>I was able to code a working solution to a proper Roman system. But I'm unable to change it so that it adapts to these new rules, particularly Rule 3. I have tried, but with no success. The way my solution is right now, for IIX, it prints 10, instead of the correct answer of 8. Here is my code (I also implemented <code>valueOf</code> for my testing):</p>
  
  <pre><code>static int romanToInt(String s) {
      char curr;
      int currVal;
      char prev;
      int prevVal;
  
      int total = valueOfRoman(s.charAt(0));
  
      for (int i = 1; i &lt; s.length(); i++) {
          curr = s.charAt(i);
          currVal = valueOfRoman(curr);
  
          prev = s.charAt(i-1);
          prevVal = valueOfRoman(prev);
  
          total += currVal;
          if(currVal &gt; prevVal) {
              total = total - (2*prevVal);
          }
  
      }
      return total;
  }
  
  
  static int valueOfRoman(char c) {
      if (c == 'M') {
          return 1000;
      } else if (c == 'D') {
          return 500;
      } else if (c == 'C') {
          return 100;
      } else if (c == 'L') {
          return 50;
      } else if (c == 'X') {
          return 10;
      } else if (c == 'V') {
          return 5;
      } else if (c == 'I') {
          return 1;
      } 
  
      return -1;
  }
  </code></pre>
  
  <p>Any help is really appreciated. Specially useful would be if you can tell me how to modify my code. Thanks!</p>
  
  <p>EDIT: I edited the names of the methods so they are clearer.</p>