roman-numerals

Trouble implementing a recursive call in C

℡╲_俬逩灬. 提交于 2020-03-28 03:30:21
问题 So I'm I've been working with C for the very first time, and I think I'm having trouble using recursion. For instance, to return a value for a recursive call in C#, I might use return methodRecursiveCall(parameter) . In C, I have this statement, which is a part of a roman numeral converter: int convert(char *s) { int val = 0; int index = 0; int length = strlen(s); while (length >1) { if (s[index] == 'I') { if(s[index + 1] == 'V' || s[index + 1] == 'X' || s[index + 1] == 'C' || s[index + 1] ==

I am trying to figure out how to convert roman numerals into integers

孤街浪徒 提交于 2020-01-01 09:53:26
问题 I am trying to figure out how to convert roman numerals to integers. This is a portion of my code. When I prompt the user to enter M it shows 1000, but when I prompt the user to enter a roman numeral such as VM, it does not give me 995 but instead 1005. This is because I am telling my program to do just that. What I am trying to figure out is how I can look ahead and get it to know when it is adding or subtracting roman numerals. How do I begin to go about doing this? class Roman { public int

How do you match only valid roman numerals with a regular expression?

旧巷老猫 提交于 2019-12-25 18:53:11
问题 Thinking about my other problem, i decided I can't even create a regular expression that will match roman numerals (let alone a context-free grammar that will generate them) The problem is matching only valid roman numerals. Eg, 990 is NOT "XM", it's "CMXC" My problem in making the regex for this is that in order to allow or not allow certain characters, I need to look back. Let's take thousands and hundreds, for example. I can allow M{0,2}C?M (to allow for 900, 1000, 1900, 2000, 2900 and

Converting Integers to Roman Numerals - Java

那年仲夏 提交于 2019-12-17 03:24:16
问题 This is a homework assignment I am having trouble with. I need to make an integer to Roman Numeral converter using a method. Later, I must then use the program to write out 1 to 3999 in Roman numerals, so hardcoding is out. My code below is very bare-bones; it is a basic I/O loop with a way to exit while using a package for getIntegerFromUser we made in class. Is there a way to assign values to Strings and then add them together when I call the method? Update: I got some pseudo code from my

Prolog Roman Numerals (Attribute Grammars)

柔情痞子 提交于 2019-12-12 12:24:30
问题 I am working on an assignment in prolog that scans a list of numerals and should return whether the list is a valid roman numeral and the decimal value of the numerals. Ex) 1 ?- roman(N, ['I'], []). N = 1 true. 2 ?- When I run the program that I feel should work, the decimal value is always right, so I'm guessing I got the synthesized attributes part right, but it always returns false for numeral lists that should return true. I'd also like to add that it aborts when it is supposed to if more

Matching Roman Numbers

对着背影说爱祢 提交于 2019-12-12 09:42:48
问题 I have regular expression (IX|IV|V?I{0,3}|M{1,4}|CM|CD|D?C{1,3}|XC|XL|L?X{1,3}) I use it to detect if there is any roman number in text. eregi("( IX|IV|V?I{0,3}[\.]| M{1,4}[\.]| CM|CD|D?C{1,3}[\.]| XC|XL|L?X{1,3}[\.])", $title, $regs) But format of roman number is always like this: " IV."... I have added in eregi example white space before number and "." after number but I still get the same result. If text is something like "somethinvianyyhing" the result will be vi (between both)... What am

Converting Roman Numerals to Int - Getting the Wrong Output - Why?

久未见 提交于 2019-12-11 08:35:18
问题 Here is my code. First, I want to say, I have been experimenting, so if you see unnecessary variables here and there, that's why. But the main part of my code is in the function decimal in my class romanType. When I input certain roman numerals, I am not getting the exact numbers I want and it might be in my logic somewhere in my if/else statements. By the way, to show how I traverse the string - I do it by reverse traversing. I go from the very end of the string to the very beginning of the

MySQL Custom Function to Turn Roman Numeral Into Arabic

亡梦爱人 提交于 2019-12-06 09:25:23
Ok, I need a MySQL Function that will convert a Roman Numeral String: e.g. XXCVI Into its Arabic numbering equivalent. Its a long story as to why I need it, I just do. Based on a PHP function that someone posted, I created the following MySQL Function, but it seems to be running endlessly and I'm not sure why. (I might just be too tired) Anybody have any hints as to what's wrong with my function, or have a more efficient way to convert a roman numeral string into an Arabic number? DROP FUNCTION IF EXISTS `romeToArabic`$$ CREATE DEFINER=`root`@`localhost` FUNCTION `romeToArabic`(roman_in

latex: printing a variable in roman numerals

最后都变了- 提交于 2019-12-05 23:35:41
问题 I'm typesetting in LaTeX, and I'd like to display a "variable" (in my case, a reference \ref{blah} to an item number in list) in roman rather than the default arabic. Is there an easy way to do this? Thanks for any pointers! 回答1: You can try \def\theenumi{\roman{enumi}} inside an enumerate environment -- this changes both labels and refs, but you'll have to then explicitly undo it (if you want to). 回答2: lowercase \romannumeral 0\ref{blah}\relax uppercase \uppercase\expandafter{\romannumeral 0

Numbers to Roman Numbers with php

只谈情不闲聊 提交于 2019-12-03 18:48:15
问题 I need to transform ordinary numbers to Roman numerals with php and I have this code: <?php function roman2number($roman){ $conv = array( array("letter" => 'I', "number" => 1), array("letter" => 'V', "number" => 5), array("letter" => 'X', "number" => 10), array("letter" => 'L', "number" => 50), array("letter" => 'C', "number" => 100), array("letter" => 'D', "number" => 500), array("letter" => 'M', "number" => 1000), array("letter" => 0, "number" => 0) ); $arabic = 0; $state = 0; $sidx = 0;