标签:repeat important ash ack color har none hash ++
int romanToInt(char * s){ int* hash = (int*)calloc(26,sizeof(int)); hash[‘I‘-65] = 1; hash[‘V‘-65] = 5; hash[‘X‘-65] = 10; hash[‘L‘-65] = 50; hash[‘C‘-65] = 100; hash[‘D‘-65] = 500; hash[‘M‘-65] = 1000; int sum=0; for (int i=0; i<strlen(s)-1; i++) { sum+=(hash[s[i]-65] >= hash[s[i+1]-65])?hash[s[i]-65]:-hash[s[i]-65]; } sum+=hash[s[strlen(s)-1]-65]; return sum; }
标签:repeat important ash ack color har none hash ++
原文地址:https://www.cnblogs.com/ganxiang/p/13626100.html