mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
problem 13
This commit is contained in:
parent
e5101e1038
commit
2b4ee7ac57
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* \brief [3. Integer to roman](https://leetcode.com/problems/integer-to-roman/)
|
* \brief [12. Integer to
|
||||||
* solution
|
* roman](https://leetcode.com/problems/integer-to-roman/) solution \details
|
||||||
* \details Given an integer, convert it to a roman numeral.
|
* Given an integer, convert it to a roman numeral.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* \brief [13. Roman to
|
||||||
|
* Integer](https://leetcode.com/problems/roman-to-integer/)
|
||||||
|
* solution
|
||||||
|
* \details Given a roman numeral, convert it to an integer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert a given roman numeral string to integer.
|
||||||
|
*
|
||||||
|
* @param s roman numeral string
|
||||||
|
* @return converted integer
|
||||||
|
*/
|
||||||
int romanToInt(char *s)
|
int romanToInt(char *s)
|
||||||
{
|
{
|
||||||
int romanToInt = 0;
|
int romanToInt = 0;
|
||||||
@ -56,3 +75,23 @@ int romanToInt(char *s)
|
|||||||
}
|
}
|
||||||
return romanToInt;
|
return romanToInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Main function
|
||||||
|
* @return 0
|
||||||
|
*/
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
assert(romanToInt("III") == 3);
|
||||||
|
printf("Test 1 passed\n");
|
||||||
|
assert(romanToInt("IV") == 4);
|
||||||
|
printf("Test 2 passed\n");
|
||||||
|
assert(romanToInt("IX") == 9);
|
||||||
|
printf("Test 3 passed\n");
|
||||||
|
assert(romanToInt("LVIII") == 58);
|
||||||
|
printf("Test 4 passed\n");
|
||||||
|
assert(romanToInt("MCMXCIV") == 1994);
|
||||||
|
printf("Test 5 passed\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user