编写程序来解析分子并获得原子数。示例...输入(字符串)输出(映射)C6H12OH {C = 6,O = 1,H = 13} fe2cl3 {cl = 3,fe = 2} [英] Write a program to parse the molecule and get the atoms count. Example...input (string) output (map) C6H12OH {C=6, O=1, H=13} fe2cl3 {cl=3, fe=2}

查看:182
本文介绍了编写程序来解析分子并获得原子数。示例...输入(字符串)输出(映射)C6H12OH {C = 6,O = 1,H = 13} fe2cl3 {cl = 3,fe = 2}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以帮我写上面这个节目。



我尝试过的事情:



i已经尝试过,但是无法做到。

you can help me to write this above program.

What I have tried:

i have tried , but not able to do.

推荐答案

如果你停下来思考它,这不是一个难题。

- 创建两个数组,一个用于保存字符,另一个用于保存值。

- 依次从字符串中取出每个字符。

- 如果数组中不存在该字符,然后将其添加到数组中。

- 将整数变量设置为1.

- 如果字符后跟一个或多个数字,然后将整数变量设置为数字的值。

- 将整数变量的值添加到与当前字符条目对应的值。

- 重复直到字符串结束。



唯一的问题是你如何决定一个元素是否有多个字符来代表它。
This is not a difficult problem if you stop and think about it.
- Create two arrays, one to hold the characters and one to hold the values.
- Take each character from the string in turn.
- If the character does not exist in the array, then add it to the array.
- Set an integer variable to 1.
- If the character is followed by one or more digits, then set the integer variable to the value of the digits.
- Add the value of the integer variable to the value corresponding to the current character entry.
- Repeat until the end of the string.

The only problem is how you decide whether an element has more than one character to represent it.


这篇关于编写程序来解析分子并获得原子数。示例...输入(字符串)输出(映射)C6H12OH {C = 6,O = 1,H = 13} fe2cl3 {cl = 3,fe = 2}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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