zoukankan      html  css  js  c++  java
  • hihocoder #1566 : 皇室成员的名字

    把每个罗马数字转化成 阿拉伯数字

    其实每次做做最长匹配就行

    然后sort 

    #include<cstdio>
    #include<cstring>
    #include<map>
    #include<iostream>
    #include<algorithm>
    #include<math.h>
    #include<map>
    #include<queue>
    #include<set>
    #include<vector>
    using namespace std;
    
    
    #define inf  1000000007
    #define ll long long
    #define MAXN   500010
    
    string s[35]={"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"};
    int  z[35]={     1,  2,    3,    4,  5,   6,   7,     8,    9, 10,  20  ,30,   40,  50 ,60,  70,    80,   90, 100, 200 ,300, 400 ,500, 600 ,700 , 800,  900 ,1000,2000,3000 };
    
    
    struct node
    {
        string a,c;
        int b;
    }y[MAXN];
    
    int calc(string b)
    {
        int len=b.size();
        int sum=0;
        for(int i=0;i<len;)
        {
            int k=i;
            string a="";
            int mx=0;
    
            while(k<len)
            {
                a+=b[k];
                int ind=-1;
                for(int j=0;j<30;j++)
                {
                    if(a==s[j])
                    {
                        ind=j;
                        break;
                    }
                }
                if(ind==-1)
                {
                    break;
                }
                else
                    mx=z[ind];
                k++;
            }
            sum+=mx;
            i=k;
     //     cout<<i<<" "<<mx<<endl;
        }
        return sum;
    }
    
    bool cmp(node a,node b)
    {
        if(a.a==b.a)
            return a.b<b.b;
        return (a.a<b.a);
    }
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1;i<=n;i++)
            {
                string b;
                cin>>y[i].a>>b;
                y[i].c=b;
                y[i].b=calc(b);
            }
            sort(y+1,y+n+1,cmp);
            for(int i=1;i<=n;i++)
                cout<<y[i].a<<" "<<y[i].c<<endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    [2018福大至诚软工助教]原型设计+用户规格说明书小结
    高等数理逻辑大作业
    [2018福大至诚软工助教]测试与优化小结
    [2018福大至诚软工助教]结对项目小结
    BETA 版冲刺前准备
    Alpha冲刺之事后诸葛亮
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
  • 原文地址:https://www.cnblogs.com/cherryMJY/p/7797329.html
Copyright © 2011-2022 走看看