求大佬帮忙看一下
java吧
全部回复
仅看楼主
level 5
2018年04月10日 11点04分 1
level 5
结果不对,而且不会调试,求大佬帮一下啊
2018年04月10日 11点04分 3
level 5
整了一下午了,头晕
2018年04月10日 11点04分 4
level 10
你这是c[喷]
2018年04月10日 11点04分 5
c语言吧没人理[喷]
2018年04月10日 12点04分
@哥不是很想说话 感觉不难,用到的不过我没明白他说的啥,高中化学都忘了[不高兴]
2018年04月10日 12点04分
@哝哝哦哦喔喔 哈哈 我是看懂了不会做
2018年04月11日 00点04分
level 5
额。。。进错吧了。。打扰了各位
2018年04月10日 11点04分 7
level 5
再次求助
2018年04月10日 12点04分 8
level 9
正则表达,或者数据切割,自己百度做下吧
2018年04月10日 12点04分 9
level 9
把数据按照数字分割,分割每个数据最后一位是数字,前面是字母,将字母送入一个方法中,方法归还一个值,然后相乘,思路就是这样,代码自己写
2018年04月10日 12点04分 10
额 我本来发了代码的,被吞了 等着回宿舍再给您发
2018年04月10日 13点04分
我用c语言写的 您看看楼下吧
2018年04月10日 13点04分
level 5
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int search(char *a,char (*b)[3]);
void main()
{
char a[10],temp[3],b[10][3]={"H","C","N","O","S","Na","Al","Cl","Ca","Zn"};
int m[11]={1,12,14,16,32,23,27,35,40,65};
int i=0,sum=0;
printf("输入化学式\n");
gets(a);
while(a[i]!='\0')
{
temp[0]=a[i];
i++;
if(isalpha(a[i]))//第二个字符是字母
{
temp[1]=a[i];
if(search(temp,b)!=-1)//俩字母是整体
{
i++;
if(isdigit(a[i]))//第三个字符是数字
sum+=m[(search(temp,b))]*(a[i]-'0');
else//第三个字符不是数字
{
sum+=m[search(temp,b)];
i--;
}
}
else//不是整体
{
temp[1]='\0';
i--;
sum+=m[search(temp,b)];
}
}
else//第二个字符不是字母
{
if(a[i]!='\0')
sum+=(a[i]-'0')*m[search(temp,b)];
else
{
sum+=m[search(temp,b)];
i--;
}
}
i++;
temp[0]=temp[1]='\0';
}
printf("%d\n",sum); /*char a[3]="O",b[10][3]={"H","C","N","O","S","Na","Al","Cl","Ca","Zn"};
int m[11]={1,12,14,16,32,23,27,35,40,65};
printf("%d\n",m[search(a,b)]);*/
}
int search(char *a,char (*b)[3])
{
int i;
for(i=0;i<10;i++)
{
if(strcmp(a,*(b+i))==0)
return i;
}
return -1;
}
2018年04月10日 13点04分 11
1