本网页所有文字内容由 imapbox邮箱云存储,邮箱网盘, iurlBox网页地址收藏管理器 下载并得到。
ImapBox 邮箱网盘 工具地址: https://www.imapbox.com/download/ImapBox.5.5.1_Build20141205_CHS_Bit32.exe
PC6下载站地址:PC6下载站分流下载
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox 网页视频 工具地址: https://www.imapbox.com/download/ImovieBox4.7.0_Build20141115_CHS.exe
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
 
 
 
 
 这个题目很简单,只是不了解数字与罗马数字转换关系的话就无从下手了。    题目:
 原理与思路:
罗马数字有如下符号:
 
基本字符 
I 
V 
X 
L 
C 
D 
M 
 
对应阿拉伯数字 
1 
5 
10 
50 
100 
500 
1000 
 
从前向后遍历罗马数字,如果某个数比前一个数小,则加上该数。反之,减去前一个数的两倍然后加上该数。
import java.util.Map; import java.util.HashMap; public class Solution {     public int romanToInt(String s) {  Map<Character,Integer> map=new HashMap<Character,Integer>();    map.put('I', 1);   map.put('V', 5);   map.put('X', 10);   map.put('L', 50);   map.put('C', 100);   map.put('D', 500);   map.put('M', 1000);           int i, total, pre, cur;           total = map.get(s.charAt(0));              for (i = 1; i < s.length(); i++) {               pre = map.get(s.charAt(i - 1));               cur = map.get(s.charAt(i));                  if (cur <= pre) {                   total += cur;               } else {                   total = total - pre * 2 + cur;               }           }              return total;     } }
阅读和此文章类似的: 程序员专区
官方软件产品操作指南 (170)