码迷,mamicode.com
首页 > 其他好文 > 详细

p1465 Preface Numbering

时间:2018-10-20 21:10:30      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:ios   pac   namespace   har   clu   turn   double   fine   ack   

用这个函数转成罗马数字统计就行了。

#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

标签:ios   pac   namespace   har   clu   turn   double   fine   ack   

原文地址:https://www.cnblogs.com/gaudar/p/9822829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!