C

YONAGI 发表于 1个月前 · 关联问题 分子量

include<stdio.h>

include<string.h>

double sum=0; void prt(char str,char str1,char str2,double x){

if(str1<='9'&&str1>='0'){ if(str2>='0'&&str2<='9') sum+=x*((10*str1-480)+(str2-49)); else sum+=x*(str1-49); } if(str=='C'||str=='O'||str=='N'||str=='H') sum+=x;

} int main(){

int n=0; char str[92]={0}; double x=0; scanf("%d",&n); for(int i=0;i<n&&scanf("%s",&str)!=EOF;i++){ int j=strlen(str); for(int g=0;g<j;g++){ if(str[g]=='C') x=12.01; else if(str[g]=='N') x=14.01; else if(str[g]=='H') x=1.008; else if(str[g]=='O') x=16.00; else x=0; if (x!=0) prt(str[g],str[g+1],str[g+2],x); } printf("%.3f\n",sum); sum=0; }

}

shinku 发表于 1个月前

include <stdio.h>

include <string.h>

include

int main() {

int N,i,j=0,k=0,p=0; double a[4]={12.01,1.008,16.00,14.01}; int n[4]={0}; char got,t[4]={'C','H','O','N'}; scanf("%d",&N); getchar(); for(i=0;i<N;i++){ got=getchar(); while(got!=10){ if(isdigit(got)==0){ k=0,j=0; while(got!=t[j]) j++; got=getchar(); } while(isdigit(got)){ k=k*10+got-48; got=getchar(); p=1; } if(k==0) n[j]++; if(p=1) n[j]+=k; } printf("%.3lf",a[0]*n[0]+a[1]*n[1]+a[2]*n[2]+a[3]*n[3]); printf("\n"); memset(n,0,sizeof(n)); }

}

shinku 发表于 8天前

include <stdio.h>

include <string.h>

include

int main() {

int N,i,j=0,k=0,p=0; double a[4]={12.01,1.008,16.00,14.01}; int n[4]={0}; char got,t[4]={'C','H','O','N'}; scanf("%d",&N); getchar(); for(i=0;i<N;i++){ got=getchar(); while(got!=10){ if(isdigit(got)==0){ k=0,j=0; while(got!=t[j]) j++; got=getchar(); } while(isdigit(got)){ k=k*10+got-48; got=getchar(); p=1; } if(k==0) n[j]++; if(p=1) n[j]+=k; } printf("%.3lf",1LU*a[0]*n[0]+a[1]*n[1]+a[2]*n[2]+a[3]*n[3]); printf("\n"); memset(n,0,sizeof(n)); }

}