羅馬數字變數字(Roman to Integer)

2021-08-09 15:19:04 字數 592 閱讀 9134

思路:既然知道羅馬數字裡的字元都只表示千級,百級,十級.....故乙個字元乙個字元的掃瞄,將其所對應的數字相加即可。注意小的在大的前面是相減

實現:想用c++的map容器,出錯。。。大神指導一下

map初始化:

#include#include#include#include#include#include#includeusing namespace std;

int romantoint(string s) ,,,

,,,};

int integer =0;

int i;

for(i=0;i> s;

int a=romantoint(s);

printf("%d",a);

}

switch ac**

#include#include#include#include#include#include#includeusing namespace std;

int romanswich(char c)

}int romantoint(string s)

羅馬數字求解

include include int main int n,i,s,k,sum char a 3000 while scanf s a eof n strlen a sum 0 k 1000 for i 0 iswitch a i case m s 1000 break case d s 500 ...

羅馬數字轉換

class solution object def romantoint self,s type s str rtype int 使用整數轉羅馬數的兩個列表 num tuple 1000,500,100,50,10,5,1 roman tuple m d c l x v i 使用dict和zip方法...

羅馬數字轉化

先看位置計數的定義 一種表達數字的系統,數字按照順序排列 每個數字有乙個位值,數字的值是每個數字和位值的乘積之和。電腦科學導論 p25 羅馬數字計數法 相同的數字連寫,所表示的數等於這些數字相加得到的數,如 3 小的數字在大的數字的右邊,所表示的數等於這些數字相加得到的數,如 8 12 小的數字 限...