| | so i don't really know how to do this.... so if anyone can help me,please.... THANK YOU.... |
|
|
Yo. That's kind of simple. Just check if the input only has characters from the set "I, V, X, L, C, D, M". If it doesn't, then it's not integer Roman numerals.
You can set up a while loop going through a character array with several if statements checking if the characters are any of the above. If you're trying to find out what that number IS, you can see my previous post on this topic. See if it makes sense to you. Reply back if need anything more. Yo. That's kind of simple. Just check if the input only has characters from the set "I, V, X, L, C, D, M". If it doesn't, then it's not integer Roman numerals. You can set up a while loop going through a character array with several if statements checking if the characters are any of the above. If you're trying to find out what that number IS, you can see my previous post on this topic. See if it makes sense to you. Reply back if need anything more. THANKS...but that's not enough...e.g. if i input XXXLCIM that isn't a roman number,but has characters from the set ''I,V,X,L,C,D,M''...so....?
Alright. Then set up an character array with the stuff in series, e.g. num[0] = "I", num[1] = "V", etc.
Consider the input as a string where each character is tested individually. Ok, let's see, some of the most complex statements in roman numerals: 1999 - MCMXCIX (index-wise, 7-5-7-3-5-1-3) 1444 - MCDXLIV (index-wise, 7-5-6-3-4-1-2) 1949 - MCMXLIX (index-wise, 7-5-7-3-4-1-2) 1494 - MCDXCIV (index-wise, 7-5-6-3-5-1-2) Say character n matches with index i in the array. Then character n+1 must have index less than or equal to i+2, say it has index j in the array. If j > i, then it is a standard roman numeral iff (if and only if) the preceding character was C,X, or I - because these are the only prefix numerals, otherwise it is fine. Start from n=1 and repeat test all over the string with n++ or however you want to jump n by 1.
Sorry, I really shouldn't do this (you should be doing your own homework) but I couldn't resist. It's been quite a while since I've undertaken exercises like this
CODE #include <stdio.h> #include <string.h> int main(); void repeat(char c); void check(char c); char input[] = "MMDCLXVII"; int indx = 0; int main() { repeat('M'); check('D'); repeat('C'); check('L'); repeat('X'); check('V'); repeat('I'); if (indx < strlen(input)) printf("Not a Roman Numeral\n"); else printf("Roman Numeral\n"); } //advances the indx up to three times for this character void repeat(char c) { int i; for (i=0; i<3; i++) { if(input[indx] == c) indx++; } } //advances the indx only once for this character void check(char c) { if (input[indx] == c) indx++; }
salamangkero you evil person! Why -sweet god, why- would you do homework for n00bs?
And what's more evil... you didn't return(0). This merits a FAIL. ... Actually, it's kinda nice code. That's a very clean style you have there.
salamangkero thanks a lot....
and osknockout i don't know how to write this statements in programm ''Then character n+1 must have index less than or equal to i+2, say it has index j in the array. If j > i, then it is a standard roman numeral iff (if and only if) the preceding character was C,X, or I.'' ?? and i'm sorry for being such boring...
Hey, no prob. I'm just trying to make you do your own homework. 'cause doing comp. sci. hmwk's good for ya.
And sorry for the formalistic advice also. I've been through a series of calc. and physics tests, so everything looks like theorem proving right now...
Similar Topics
Keywords : roman numbers
I want to scan prime numbers ,have you logic to solve this problem? here is example of even Looking for roman, numbers, c, c,
|
|
![]() I Need Help - it's about roman numbers in c/c++ |
| ADD REPLY / Got an Opinion! | Remove these ADs! | RAPID SEARCH! | Free Web Hosting | [X] |
|
Express your Opinions, Thoughts or Contribute more info. to help others. Ask your Doubts & Queries to get answers, So that "Together We can help others!" |
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP. | 500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE |
|