Given a Roman numeral, convert it to an integer. Input is guaranteed to being within the range from 1 to 3999.
The Roman numeral and the integer turn
Int getint (char c) { int temp; switch (c) { case ' I ':return 1; case ' V ':return 5; case ' X ': return 10; case ' L ':return 50; case ' C ': return 100; case ' D ':return 500; case ' M ':return 1000; } return 0 ;} Int romantoint (char* s) { int temp; int sum=getint (S[0]); for (Int i=1;i<strlen (s); i++) { if (getInt(S[i-1]) <getint (S[i]) { sum+=getint ( S[i]); sum-=2*getint (S[i-1]); // printf ("%d-->%d\n", GetInt (S[i-1]) , GetInt (S[i])); }else{ Sum+=getint (S[i]); // printf ("{%d} ", GetInt (S[i])); } } return sum;}
PS: At first I thought it was a summation from left to right ... The results were found to be wrong. The first thing to do is to understand the Roman numeral rules ...... I don't know now. One by one, the left side is bigger than the right, and the left side is smaller than the right one, and then minus twice times more .....
2, for the first time in the Leetcode additional definition function, to write in the previous to the function .....
Leetcode 13. Roman to Integer C language