我该如何解决C ++中的问题 [英] how can i solve this Problems in C++

查看:91
本文介绍了我该如何解决C ++中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

罗马数字系统带有符号

I V X L C D M
1 5 10 50 100 500 1000

罗马数字是通过将上述符号组合在一起并加上值而形成的.例如,MMVI是1000 + 1000 + 5 + 1 =2006.通常:
•符号按值的顺序(从最大值开始).
•当较小的值先于较大的值时,则从较大的值中减去较小的值,例如IV是4,IX是9,CM是900.
•当较小的值跟随较大的值时,较小的值将添加到较大的值,例如VIII是8,DX是510,LXX是70.
•符号I,X,C和M可以连续重复三次,但不能重复. (如果它们不连续出现,则它们可能会出现3次以上,例如XXXIX.)
•不能重复使用符号V,L和D.
•根据以下说明,可以从任何大数值符号中减去一个小数值符号:
o我只能从V和X中减去.
o X只能从L和C中减去.
o C只能从D和M中减去.
o永远不能减去V,L和D.

例子:

MCMXLIV 1000 +(1000 − 100)+(50 − 10)+(5 − 1)1944
MCMLIV 1000 +(1000 – 100)+ 50 +(5 – 1)1954
MCMXC 1000 +(1000 – 100)+(100 – 10)1990
LXXVIII 50 + 10 + 10 + 5 + 1 + 1 + 1 78
CCCLXIX 100 + 100 + 100 + 50 + 10 +(10 – 1)369
MMDCCLI 1000 + 1000 + 500 + 100 + 100 + 50 + 1 2751
DCCCXC 500 + 100 + 100 + 100 +(100 – 10)890

编写一个程序,提示用户输入代表罗马数字的符号字符串.程序将该罗马数字转换为等效的十进制数字,然后打印两个数字.

如果roman是string类型的变量,则roman [0]将第一个字符存储在字符串中,roman [1]将第二个字符存储在字符串中,roman [2]将第三个字符存储在字符串中,依此类推.

Roman numbers system has the symbols

I V X L C D M
1 5 10 50 100 500 1000

Roman Numbers are formed by combining the above symbols together and adding the values. For example, MMVI is 1000 + 1000 + 5 + 1 = 2006. Generally:
• Symbols are placed in order of value, starting with the largest values.
• When smaller values precede larger values, the smaller values are subtracted from the larger values e.g. IV is 4, IX is 9, and CM is 900.
• When smaller values follow larger values, the smaller values are added to the larger values e.g. VIII is 8, DX is 510, and LXX is 70.
• The symbols I, X, C, and M can be repeated three times in succession, but no more. (They may appear more than three times if they appear non-sequentially, such as XXXIX.)
• The symbols V, L, and D can never be repeated.
• Only one small-value symbol may be subtracted from any large-value symbol according to the following:
o I can be subtracted from V and X only.
o X can be subtracted from L and C only.
o C can be subtracted from D and M only.
o V, L, and D can never be subtracted.

Examples:

MCMXLIV 1000 + (1000 − 100) + (50 − 10) + (5 − 1) 1944
MCMLIV 1000 + (1000 – 100) + 50 + (5 – 1) 1954
MCMXC 1000 + (1000 – 100) + (100 – 10) 1990
LXXVIII 50 + 10 + 10 + 5 + 1 + 1 + 1 78
CCCLXIX 100 + 100 + 100 + 50 + 10 + (10 – 1) 369
MMDCCLI 1000 + 1000 + 500 + 100 + 100 + 50 + 1 2751
DCCCXC 500 + 100 + 100 + 100 + (100 – 10) 890

Write a program that prompts the user to enter a string of symbols representing a Roman number. The program converts that roman number to its equivalent decimal number, and then prints both numbers.

If roman is a variable of type string, then roman[0] stores the first character in the string, roman[1] stores the second character in the string, roman[2] stores the third character in the string, and so on.

推荐答案

编写一个提示用户的程序...
不,您编写程序.

这是询问者的期望:
1. 先尝试您要做什么!
2.制定看起来像问题/无法解决的问题.

试试看,告诉他们是否遇到问题.
成员将很乐意为您提供帮助.
Write a program that prompts the user...
No. You write the program.

Here is what is expected of enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


这篇关于我该如何解决C ++中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆