コード例 #1
0
ファイル: roman_integer.cpp プロジェクト: hubert-he/leetcode
int main()
{
    std::string s("XCIX");
    //std::string s("MDCCCIC");
    //std::string s("XXIV");
    //std::string s("MDCCCXCIX");
    int ret = romanToInt(s);
    std::cout << "ret=" << ret << std::endl;
    romanToInt(s, &ret);
    std::cout << "ret=" << ret << std::endl;
	std::string xx = intToRoman(15);
	std::cout << "roman = " << xx << std::endl;
    return 0;
}
コード例 #2
0
int main()
{
	char s[] = "MMMCMXCIX";
	int sum;
	sum = romanToInt(s);
	printf("sum=%d\n", sum);
}
コード例 #3
0
int main(void){
	char s[100];
	while(gets(s)){
		int result=romanToInt(s);
		printf("%d\n",result);
	}
	
}
コード例 #4
0
ファイル: c_solution.c プロジェクト: qiyon/leetcode
int main(int argc, char * argv[])
{
    if (argc < 2) {
        printf("Need arg \n");
    } else {
        printf("Roman %s to integer is %d \n", argv[1], romanToInt(argv[1]));
    }
}
コード例 #5
0
 int romanToInt(string s) {
    if (s.length() == 0)
       return 0;
    string s0;
    string s1;
    s0.push_back(s[0]);
    s1.push_back(s[1]);
    if (s0[0] == 'I' || s0[0] == 'X' || s0[0] == 'C'){
       if (s[1] == '\0')
          return list.find(s0)->second;
       int next = list.find(s1)->second;
       if (next > list.find(s0) ->second)
          return next - list.find(s0)->second + romanToInt(s.substr(2, s.length() - 2));
       else{
          return list.find(s0)->second + romanToInt(s.substr(1, s.length() - 1));
       }
    }
    else{
       return list.find(s0)->second + romanToInt(s.substr(1, s.length() - 1));
    }
 }
コード例 #6
0
/*virtual*/
bool Solution::Test()
{
    bool pass = true;

    pass = pass && (romanToInt("") == 0);
    pass = pass && (romanToInt("I") == 1);
    pass = pass && (romanToInt("II") == 2);
    pass = pass && (romanToInt("IV") == 4);
    pass = pass && (romanToInt("V") == 5);
    pass = pass && (romanToInt("VI") == 6);
    pass = pass && (romanToInt("VII") == 7);
    pass = pass && (romanToInt("VIII") == 8);
    pass = pass && (romanToInt("IX") == 9);
    pass = pass && (romanToInt("X") == 10);
    pass = pass && (romanToInt("XI") == 11);
    pass = pass && (romanToInt("XIV") == 14);
    pass = pass && (romanToInt("XV") == 15);
    pass = pass && (romanToInt("XVI") == 16);
    pass = pass && (romanToInt("XIX") == 19);
    pass = pass && (romanToInt("XX") == 20);
    pass = pass && (romanToInt("XL") == 40);
    pass = pass && (romanToInt("XLI") == 41);
    pass = pass && (romanToInt("XLIV") == 44);
    pass = pass && (romanToInt("XLV") == 45);
    pass = pass && (romanToInt("XLVI") == 46);
    pass = pass && (romanToInt("XC") == 90);
    pass = pass && (romanToInt("XCIX") == 99);
    pass = pass && (romanToInt("C") == 100);

    return pass;
}
コード例 #7
0
ファイル: 13.cpp プロジェクト: shuyulxf/leetcode-srccode
int main(){
    printf("%d", romanToInt("DCXXXIV")); 

    system("pause"); 
    return 0;
}
コード例 #8
0
void testRomanToInt() {
    char *s1 = "IV";
    printf("%d", romanToInt(s1));
}
コード例 #9
0
ファイル: RomanInteger.c プロジェクト: FeifeiWang7/LeetCode
int main()
{
	printf("%d\n", romanToInt("XCIX"));
}
コード例 #10
0
ファイル: leetcode13.cpp プロジェクト: candyqinlibo/leetcode
int _tmain(int argc, _TCHAR* argv[])
{
	printf("%d\n", romanToInt("IV"));
	return 0;
}
コード例 #11
0
ファイル: roman2int.c プロジェクト: Sasasu/leetcode
int main(int argc, char *argv[])
{
	return printf("%d\n", romanToInt(argv[1]));
}
コード例 #12
0
ファイル: 13_roman_to_int.c プロジェクト: wuzhouhui/leetcode
int main(int argc, char **argv)
{
	printf("%d\n", romanToInt(argv[1]));
	return(0);
}
コード例 #13
0
int main(int argc, char *argv[])
{
    char *str = "CXLI";
    printf("%d\n", romanToInt(str));
}