p1465 Preface Numbering
Posted gaudar
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了p1465 Preface Numbering相关的知识,希望对你有一定的参考价值。
用这个函数转成罗马数字统计就行了。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #define mkp make_pair using namespace std; const double EPS=1e-8; typedef long long lon; const lon SZ=30,INF=0x7FFFFFFF; 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; } int main() { std::ios::sync_with_stdio(0); //freopen("d:\1.txt","r",stdin); lon casenum; //cin>>casenum; //for(lon time=1;time<=casenum;++time) { int n; cin>>n; map<char,int> mp; for(int i=1;i<=n;++i) { string tmp=intToRoman(i); for(int j=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的主要内容,如果未能解决你的问题,请参考以下文章