Problem:
http://ace.delos.com/usacoprob2?a=GDaP3qeGiYp&S=preface
My Answer:
/*
ID:Iby071
LANG:C++
TASK:preface
*/
#include<iostream>
#include<fstream>
using namespace std;
int main()
{ ifstream fin("preface.in");
ofstream fout("preface.out");
int i,v,x,l,c,d,m;
i=v=x=l=c=d=m=0;
int n,tmp,tmp1;
fin>>n;
for(int j=0;j<=n;++j)
{ tmp=j;
if(tmp>=1000){tmp1=tmp/1000;tmp%=1000;m+=tmp1;}
if(tmp>=900){tmp-=900;++c;++m;}
if(tmp>=500){tmp-=500;++d;}
if(tmp>=400){tmp-=400;++d;++c;}
if(tmp>=100){tmp1=tmp/100;tmp%=100;c+=tmp1;}
if(tmp>=90){tmp-=90;++x;++c;}
if(tmp>=50){tmp-=50;++l;}
if(tmp>=40){tmp-=40;++l;++x;}
if(tmp>=10){tmp1=tmp/10;tmp%=10;x+=tmp1;}
if(tmp>=9){tmp-=9;++x;++i;}
if(tmp>=5){tmp-=5;++v;}
if(tmp>=4){tmp-=4;++i;++v;}
if(tmp>=1){i+=tmp;}
}
if(i!=0) fout<<'I'<<' '<<i<<endl;
if(v!=0) fout<<'V'<<' '<<v<<endl;
if(x!=0) fout<<'X'<<' '<<x<<endl;
if(l!=0) fout<<'L'<<' '<<l<<endl;
if(c!=0) fout<<'C'<<' '<<c<<endl;
if(d!=0) fout<<'D'<<' '<<d<<endl;
if(m!=0) fout<<'M'<<' '<<m<<endl;
return 0;
}