Roman Numeral Line Segments Write a program or function that accepts an integer in the range 1..3999 as input and returns the number of line segments required to express that integer in standard Roman numerals (so you would use XL but not VM). Examples:

   1 -&gt; 1
   4 -&gt; 3
   5 -&gt; 2
   9 -&gt; 3
  10 -&gt; 2
  40 -&gt; 4
  50 -&gt; 2
  90 -&gt; 3
 100 -&gt; 1
 400 -&gt; 3
 500 -&gt; 2
 900 -&gt; 5
1000 -&gt; 4


Roman number conversion builtins are permitted, but you can solve the problem without them by repeatedly subtracting the largest remaining number from the above list. Example: 1234 = 4 + 1 + 1 + 2 + 2 + 2 + 3 = 15.

This is code-golf, so the shortest program wins.
C, 148 129 chars

d,x,n[]={1000,900,500,400,100,90,50,40,10,9,5,4,1,4,5,2,3,1,3,2,4,2,3,2,3,1};f(c){while(d+=(c/n[x])*n[x+13],c%=n[x++]);return d;}


My first code-golf :^). Since the question states I can use a function, I have changed main to a function to trim some chars (most importantly: pass c as parameter rather scanf)

unpacked

d,x,n[]={1000,900,500,400,100,90,50,40,10,9,5,4,1,4,5,2,3,1,3,2,4,2,3,2,3,1};
f(c){
  while(d+=(c/n[x])*n[x+13],
        c%=n[x++]);
  return d;
}