/Convert roman to decimal
#include<stdio.h>

int convert(char *s, int len)
{
  int i = 0, d = 0, prev = 0;
  for(;i < len; i++)
  {
    switch(*(s+i))
    {
      case 'i': d += 1;
        break;
      case 'v': if(i!=0 && *(s+prev) == 'i')
        {
          d = d + 5 - 2;
        }
        else
          d += 5;
          break;
      case 'x': if(i!=0 && *(s+prev) == 'i')
        {
          d = d + 10 - 2;
        }
        else
          d += 10;
        break;
    }
    prev = i;
  }
  return d;
}
main()
{
  char s[] = "xix";
  int len = 0, d;
  while(s[len] != '\0')
    len++;
  len++;
  d = convert((char *)s,len);
  printf("%d\n", d);
}


On Sun, Nov 6, 2011 at 11:15 AM, rahul sharma <[email protected]>wrote:

> i.p: v
> o/p 5
> i/p ix
> o/p:9
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Vandana Bachani
Graduate Student, MSCE
Computer Science & Engineering Department
Texas A&M University, College Station

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to