problem 13

This commit is contained in:
Krishna Vedala 2020-10-30 17:26:37 +05:30
parent e5101e1038
commit 2b4ee7ac57
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
2 changed files with 43 additions and 4 deletions

View File

@ -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>

View File

@ -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;
@ -55,4 +74,24 @@ 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;
}