直接for循环,并且判断是否出现IV等情况
int which(char ch){ if(ch == 'I') return 1; else if(ch == 'V') return 5; else if(ch == 'X') return 10; else if(ch == 'L') return 50; else if(ch == 'C') return 100; else if(ch == 'D') return 500; else return 1000;}class Solution {public: int romanToInt(string s) { int flag = 0; int ans = 0; for(int i=0; i