zoukankan      html  css  js  c++  java
  • 罗马数字转化

    IV=4

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    char ss[1000];
    int main()
    {
        while(cin>>ss)
        {  int sum=0;;
            for(int i=0; i<strlen(ss); i++)
            {
    
                switch(ss[i])
                {
                case'M':
                    sum+=1000;
                    break;
                case'D':
                    sum+=500;
                    break;
                case'C':
                    if(ss[i+1]=='D'||ss[i+1]=='M')
                        sum-=100;
                    else sum+=100;
                    break;
                case'L':
                    sum+=50;
                    break;
                case'X':
                    if(ss[i+1]=='L'||ss[i+1]=='C')
                        sum-=10;
                    else sum+=10;
                    break;
                case'I':
                    if(ss[i+1]=='X'||ss[i+1]=='V')
                        sum-=1;
                    else sum+=1;
                    break;
                }
    
            }
            cout<<sum<<endl;
        }
    }
    

      6=VI

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main()
    {
        int  n;
        while(cin>>n)
        {
            char* one[15]= {"","I","II","III","IV","V","VI","VII","VIII","IX"};
            char* ten[15] = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
            char* hundreds[15] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
            char* thousand[5] = {"","M","MM","MMM"};
            cout<<thousand[n/1000];
            cout<<hundreds[n%1000/100];
            cout<<ten[n%100/10];
            cout<<one[n%10];
        }
    
    }
    

      

  • 相关阅读:
    vue-实践1
    node 基本使用
    vue通信
    初始AMD和Common.js
    vue正确引入第三方包
    常见的java设计模式
    springboot加ES实现全局检索
    Cookie丢失的原因
    动态SQL
    用Java实现给图片添加文字
  • 原文地址:https://www.cnblogs.com/sxy-798013203/p/5694816.html
Copyright © 2011-2022 走看看