题意:给定一个只由H、C、O三种分子组成物质的分子式,求相对分子质量
len<=10
思路:队友写的
1 #include <stdio.h> 2 #include <vector> 3 #include <algorithm> 4 #include <string.h> 5 #include <limits.h> 6 #include <string> 7 #include <iostream> 8 #include <queue> 9 #include <math.h> 10 #include <stack> 11 #include <map> 12 #define left (now<<1) 13 #define right ((now<<1)+1) 14 #define mid ((l+r)>>1) 15 using namespace std; 16 typedef long long int lint; 17 18 int n,t; 19 const int MAXN = 1e5 + 10; 20 21 char str[MAXN]; 22 23 int main(){ 24 scanf("%d",&t); 25 while(t--){ 26 scanf("%s",str); int len = strlen(str); lint ans = 0; 27 for(int i = 0; i < len; ++i){ 28 if(str[i] == 'H'){ 29 ++ans; 30 }else if(str[i] == 'C'){ 31 ans += 12; 32 }else{ 33 ans += 16; 34 } 35 } 36 printf("%I64d ",ans); 37 } 38 return 0; 39 }