Use this function to convert to Roman numeral statistics on the line.
#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<vector>#include<iomanip>#include<cstring>#include<map>#include<queue>#include<Set>#include<cassert>#include<stack>#defineMKP Make_pairusing namespacestd;Const Doubleeps=1e-8; typedefLong LongLon;ConstLon sz= -, inf=0x7FFFFFFF;stringInttoroman (intnum) { stringc[4][Ten]={ {"","I","II","III","IV","V","VI","VII","VIII","IX"}, {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"}, {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}, {"","M","MM","MMM"}}; stringRoman; Roman.append (c[3][num/ +%Ten]); Roman.append (c[2][num/ -%Ten]); Roman.append (c[1][num/Ten%Ten]); Roman.append (c[0][num%Ten]); returnRoman; }intMain () {Std::ios::sync_with_stdio (0); //freopen ("D:\\1.txt", "R", stdin);Lon Casenum; //cin>>casenum; //For (Lon Time=1;time<=casenum;++time) { intN; CIN>>N; Map<Char,int>MP; for(intI=1; i<=n;++i) {stringtmp=Inttoroman (i); for(intj=0; J<tmp.size (); + +j) {++Mp[tmp[j]]; } } if(mp['I']) cout<<'I'<<" "<<mp['I']<<Endl; if(mp['V']) cout<<'V'<<" "<<mp['V']<<Endl; if(mp['X']) cout<<'X'<<" "<<mp['X']<<Endl; if(mp['L']) cout<<'L'<<" "<<mp['L']<<Endl; if(mp['C']) cout<<'C'<<" "<<mp['C']<<Endl; if(mp['D']) cout<<'D'<<" "<<mp['D']<<Endl; if(mp['M']) cout<<'M'<<" "<<mp['M']<<Endl; } return 0;}
string inttoroman (int num) {
String c[4][10]={
{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
{"", "M", "MM", "MMM"}};
String Roman;
Roman.append (c[3][num/1000% 10]);
Roman.append (c[2][num/100% 10]);
Roman.append (c[1][num/10% 10]);
Roman.append (c[0][num% 10]);
return Roman;
}
p1465 Preface numbering