public static int romanToInt(String s) {
		Character[] metric = {'I','V','X','L','C','D','M'};
		int[] a = {1,5,10,50,100,500,1000};
		Map<Character, Integer> smap = new HashMap<Character, Integer>();
		for (int i = 0; i < metric.length; i++) {
			smap.put(metric[i], a[i]);
		}
		int res = 0;
		for (int i = 0; i < s.length(); i++) {
			if (i == s.length() - 1) res = res + smap.get(s.charAt(i));
			else {
				int ai = smap.get(s.charAt(i));
				int bi = smap.get(s.charAt(i + 1));
				if (ai < bi) {
					res = res + bi - ai;
					i = i + 1;
				} else {
					res = res + ai;
				}
			}
		}
    	return res;
    }