题目描述
罗马数字转整数,包含以下七种字符: I, V, X, L,C,D 和 M。分别对应1,5,10,50,100,500,1000。
- I 可以放在 V (5) 和 X (10) 的左边,来表示 4 和 9。
- X 可以放在 L (50) 和 C (100) 的左边,来表示 40 和 90。
- C 可以放在 D (500) 和 M (1000) 的左边,来表示 400 和 900。
给定一个罗马数字,将其转换成整数。输入确保在 1 到 3999 的范围内。
思路
将每一个对应罗马数字转换成数字,一个一个加起来。当小数字在大数字前时,需要减法。
eg:罗马数字IV,就是V-I,即5-1=4,其他正常叠加
难点
数字转换
方法
使用数组,给每一个罗马数字对应下标,每个下标在数组中对应值。
int romanToInt(char * s){
int num[26];// 优点在于利用ASCII码,数组空间尽可能小,也更能理解
num['I' - 'A'] = 1;
num['V' - 'A'] = 5;
num['X' - 'A'] = 10;
num['L' - 'A'] = 50;
num['C' - 'A'] = 100;
num['D' - 'A'] = 500;
num['M' - 'A'] = 1000;
int result = 0, len = strlen(s);
for(int i = 0; i < len; i++){
int value = num[s[i] - 'A'];
if(i < len-1 && value < num[s[i+1] - 'A']){
result -= value;
}else{
result += value;
}
}
return result;
}
java版本(题解中一个很好的思路)
该方法避免了在数字相加时进行判断,直接++
class Solution {
public int romanToInt(String s) {
// 优点在于将6种较为特殊的情况提前转化,在switch中进行判断即可,避免了小数字在大数字前的判断,且减少了switch语句判断的次数。
// 缺点在于当特例足够多时,会变得臃肿,不及+-判断精简
s = s.replace("IV","a");
s = s.replace("IX","b");
s = s.replace("XL","c");
s = s.replace("XC","d");
s = s.replace("CD","e");
s = s.replace("CM","f");
int result = 0;
for(int i = 0;i < s.length(); i++){
result += getValue(s.charAt(i));
}
return result;
}
private int getValue(char c) {
switch(c) {
case 'I' : return 1;
case 'V' : return 5;
case 'X' : return 10;
case 'L' : return 50;
case 'C' : return 100;
case 'D' : return 500;
case 'M' : return 1000;
case 'a' : return 4;
case 'b' : return 9;
case 'c' : return 40;
case 'd' : return 90;
case 'e' : return 400;
case 'f' : return 900;
}
return 0;
}
}
吐槽一下个人代码问题
- 习惯于return 0,导致运行结果不符合预期,多return了一个0
- 大小写问题,V和v的问题,导致ASCII码变化,计算结果不符合预期
本文由 szr 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Sep 14, 2021 at 07:44 pm
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: сервисные центры по ремонту техники в мск
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: ремонт бытовой техники в мск
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
|There are hundreds of thousands of hair accessory possibilities. You can choose from lots of options, including headbands, scrunchies, bows, barrettes and extensions. Include various hair accessories for practical and aesthetic purposes. The right hair accessory can set off an entire outfit. When you are going out on the town, choose a headband that compliments your outfit.
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
xnxx porn
By the 1960s, lingerie manufacturers introduced lingerie to the forefront and began glamorizing sleek and sexy undergarments.
Each of those numbers will ensure that the lacy bra and panties you purchase her can be the correct dimension while there may be typically a little bit variation between different lingerie
manufacturers or bra kinds. The best approach to
gauge whether or not or not she is going to in all probability put your lingerie give to good use is just by taking observe of the styles she already wears by far the most.
Searching for the intimate wears that may compliment in addition to accentuate the boldness?
You will note a measurement in inches indicating the chest width as nicely as one thing called
cup dimension which is 2 letters from the alphabet like "DD" preceded by
numbers like "33". There are loads of internet sites that supply
plus dimension lingerie as a lot as size 6x and a few offer size even larger,
so if you are a really full figured woman, you may easily find
your excellent dimension in plus measurement leather-based lingerie.
If you're hoping to taste up your individual
life, or the life of your accomplice, you can do as such with
carrying a good lingerie dress. And this is the time when each girl tries to develop into the woman of the dreams
of her husband with whom she has vowed to live her whole life.
Anyone who has spent a lot of time shopping through
a lingerie store ultimately finds out that although the shop is perhaps have the usual bras, panties and underwear, plus size lingerie and elaborate designs are nearly at all times by no means in inventory.
Having this sort of piece does not really mean that you are on the go for a one sizzling evening on a regular basis
but additionally it is one thing you probably can put on to really feel sexy and stunning whilst you sleep.
All bride bodies have completely different shapes,
and all brides want to really feel sexy at their marriage ceremony evening time.
As soon as many buddies received together, somebody requested:
"What kind of clothes do you might have most in your wardrobe?" Every man has his hobbyhorse.
Folks who really know the easiest way to gown up, shouldn't only concentrate on clothes,
more consideration should be paid to the clothes inside.
If wear underwear too casually, then cannot make nice clothes to maximise the
operate.
https://dianoetic.net/solar-energy-storage-education-batteries-for-solar-panels/ ATGepower
https://Renewagen.org/portable-power-stations/ ATGepower
Since its inception, “Sunlit Aiko” has grown into a trusted platform for solar power
enthusiasts globally. Aiko’s engaging writing style combined with her
in-depth knowledge of the solar industry makes her
blog a go-to resource for anyone interested in harnessing
the power of the sun.
https://leotaxil.com/portable-energy-storage-device/ ATGepower
https://Energizenow.online/low-budget-office-light-fixtures-commercial-led-lighting/ ATGepower
Upon graduation, Aiko worked as a Renewable Energy Analyst in one of Japan’s
leading energy firms. However, her desire to share
her knowledge and advocate for solar power led her to leave her corporate job and start her own blog
– “Sunlit Aiko”.