问题是这样的,比如水的化学式是H2O,表示出来是这样;
'H2O' would return
'H', 'O' (the elements)
2, 1 (the number of atoms)
'NaCl' would return
'Na', 'Cl' and 1, 1
'C2H5OH' returns
'C', 'H', 'O' and 2, 6, 1.
下面的代码可以完成楼主的功能要求,以备参考。#include #include #include using namespace std;void Output(char *molecular_formula);void main(int argc, char *argv[]){ int i; for(i = 1; i < argc; i++) {Output(argv); }}void Output(char *molecular_formula){ int k = 0; int n = 0; char