|
|
|
|
![]() ![]() |
Mar 26 2008, 08:16 PM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 3 Joined: 26-March 08 From: Croatia Member No.: 59,895 |
so i don't really know how to do this.... so if anyone can help me,please.... THANK YOU.... |
|
|
|
Mar 27 2008, 04:40 AM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 380 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
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. This post has been edited by osknockout: Mar 27 2008, 04:40 AM |
|
|
|
Mar 27 2008, 07:03 PM
Post
#3
|
|
|
Newbie ![]() Group: Members Posts: 3 Joined: 26-March 08 From: Croatia Member No.: 59,895 |
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....? |
|
|
|
Mar 28 2008, 02:45 AM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 380 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
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. |
|
|
|
Mar 28 2008, 02:55 AM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 434 Joined: 15-August 06 From: Philippines Member No.: 28,387 |
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++; } |
|
|
|
Mar 28 2008, 03:07 AM
Post
#6
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 380 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
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. |
|
|
|
Mar 28 2008, 08:48 PM
Post
#7
|
|
|
Newbie ![]() Group: Members Posts: 3 Joined: 26-March 08 From: Croatia Member No.: 59,895 |
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... |
|
|
|
Mar 29 2008, 10:42 PM
Post
#8
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 380 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
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
| Topics | Topics | |
|---|---|---|
|
|
|