GDUFE ACM-1356

题目:http://acm.gdufe.edu.cn/Problem/read/id/1356

Problem B. Relative atomic mass

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

Relative atomic mass is a dimensionless physical quantity, the ratio of the average mass of atoms of an element (from a single given sample or source) to 1/12 of the mass of an atom of carbon-12 (known as the uni?ed atomic mass unit). You need to calculate the relative atomic mass of a molecule, which consists of one or several atoms. In this problem, you only need to process molecules which contain hydrogen atoms, oxygen atoms, and carbon atoms. These three types of atom are written as ’H’, ’O’ and ’C’ repectively. For your information, the relative atomic mass of one hydrogen atom is 1, and the relative atomic mass of one oxygen atom is 16 and the relative atomic mass of one carbon atom is 12. A molecule is demonstrated as a string, of which each letter is for an atom. For example, a molecule ’HOH’ contains two hydrogen atoms and one oxygen atom, therefore its relative atomic mass is 18 = 2?1 + 16. 

Input:

The ?rst line of input contains one integer N(N ≤ 10), the number of molecules. In the next N lines, the i-th line contains a string, describing the i-th molecule. The length of each string would not exceed 10. 

Output:

For each molecule, output its relative atomic mass. 

Sample Input:

5
H
C
O
HOH
CHHHCHHOH

Sample Output:

1
12
16
18
46

思路:判断遇到的字符是哪一个,如果遇到‘H‘则+1,如果遇到‘C‘则+12,如果遇到‘O‘则+16

难度:非常简单

代码:
 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     int n,i,sum,k;
 6     char a[11];
 7     while(scanf("%d",&n)!=EOF)
 8     {
 9         while(n--)
10         {
11             sum=0;
12             scanf("%s",&a);
13             k=strlen(a);
14             for(i=0;i<k;i++)
15             {
16                 if(a[i]==‘H‘)
17                     sum+=1;
18                 else if(a[i]==‘O‘)
19                     sum+=16;
20                 else if(a[i]==‘C‘)
21                     sum+=12;
22             }
23             printf("%d\n",sum);
24         }
25     }
26     return 0;
27 }
时间: 2024-12-16 18:55:56

GDUFE ACM-1356的相关文章

http://acm.gdufe.edu.cn/Problem/read/id/1007

递推题目系列之一涂色问题 Time Limit: 2000/1000ms (Java/Others) Problem Description 有排成一行的n个方格,用红(Red).粉(Pink).绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法. Input: 输入数据包含多个测试实例,每个测试实例占一行,由一个整数N组成,(0<n<=50). Output: 对于每个测试实例,请输出全部的满足要求的涂法,每个实例的输出占一行.

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

GDUFE ACM-1087

题目:http://acm.gdufe.edu.cn/Problem/read/id/1087 辉辉的一天 Time Limit: 2000/1000ms (Java/Others) Problem Description: 辉辉.姗姗和佳佳是好朋友,他们一起参加了在湖南长沙长郡中学举办的第二十一届全国青少年信息学奥林匹克竞赛(NOI2004).他们很早就来到了长沙,可是报名还没有开始.怎么办呢?他们决定分头出去玩一天,晚上回到宿舍以后给大家说说自己这一天做了什么有意义的事情. 你一定想不到辉辉

GDUFE ACM-1050

题目:http://acm.gdufe.edu.cn/Problem/read/id/1050 a/b + c/d Time Limit: 2000/1000ms (Java/Others) Problem Description: 给你2个分数,求他们的和,并要求和为最简形式. Input: 输入首先包含一个正整数T(T<=1000),表示有T组测试数据,然后是T行数据,每行包含四个正整数a,b,c,d(0<a,b,c,d<1000),表示两个分数a/b 和 c/d. Output:

GDUFE ACM-1028 回文串

题目:http://acm.gdufe.edu.cn/Problem/read/id/1028 Problem Description: “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”. Input: 输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串. Output: 如果一个字符串是回文串,则输出"yes",否则输出"no". S

GDUFE ACM-1019 Repeating Characters

题目:http://acm.gdufe.edu.cn/Problem/read/id/1019 Problem Description: For this problem, you will write a program that takes a string of characters, S, and creates a new string of characters, T, with each character repaeated R times. That is, R copies

GDUFE ACM-1039

题目:http://acm.gdufe.edu.cn/Problem/read/id/1039 寒冰王座 Time Limit: 2000/1000ms (Java/Others) Problem Description: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前. 死亡骑士:"我要买道具!" 地精商人:"我们这里有三种道具,血瓶150块一个,魔法药200块一个,无

GDUFE ACM-1044

题目:http://acm.gdufe.edu.cn/Problem/read/id/1044 青年歌手大奖赛_评委会打分 Time Limit: 2000/1000ms (Java/Others) Problem Description: 青年歌手大奖赛中,评委会给参赛选手打分.选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分. Input: 输入数据有多组,每组占一行,每行的第一个数是n(2<n<=100),表示评委的人数,然后是n个评委的打分. Outp

GDUFE ACM-1038

题目:http://acm.gdufe.edu.cn/Problem/read/id/1038 抢糖果 Time Limit: 2000/1000ms (Java/Others) Problem Description: 今天计实班的生活委员心情大好,在永诚超市狂购了好多好多糖果,好开心~o(∩_∩)o 刚付完款,她就遇到吃货吖杰,被他剥削了一半的糖果\("▔□▔)/还好此货良心未泯,又还给了生活委员糖果...一颗,就厚着脸皮走了(︶︿︶) 刚踏出超市大门,她就遇到了坑货吟姐,又被剥削了一半!还