帮我跑一下代码
  • 板块题目总版
  • 楼主taehyang
  • 当前回复7
  • 已保存回复7
  • 发布时间2022/8/2 11:40
  • 上次更新2023/10/27 17:23:57
查看原帖
帮我跑一下代码
669946
taehyang楼主2022/8/2 11:40

有没有好心人帮我跑一下UVA1586,我没有账号跑不了,注册不了账号

// 习题 3-2 分子量

#include<stdio.h>
#include<string.h>

char s[1000];
int n;

bool A(char ch){
	switch(ch){
		case 'C':
		case 'H':
		case 'O':
		case 'N':return true;
		default:return false; 
	}	
}

float getAw(char ch){
	switch(ch){
		case 'C':return 12.01;
		case 'H':return 1.008;
		case 'O':return	16.00;
		case 'N':return 14.01; 
	}
}

int main(){
	scanf("%d", &n);
	fflush(stdin);
	while(n--){
		//printf("%d:\n", n+1);
		float total = 0;
		gets(s);
		for(int i=0;i<strlen(s);i++){
			if(A(s[i])){
				int sum=0;
				bool isNum = false;
				for(int j=i+1;j<strlen(s);j++)
					if(!A(s[j])){
						sum = sum*10+s[j]-'0';
						isNum = true;
					}
					else
						break;
				if(!isNum)
					sum=1;
				total += sum*getAw(s[i]);
			}
			
		}
		printf("%.3f\n", total);
	}
	return 0;
} 
2022/8/2 11:40
加载中...