Last Submissions | ||||||
---|---|---|---|---|---|---|
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
| discuss1586 - | Accepted | C++11 | 0.000 | 0.000 | 5227 | 1 mins ago |
Problem:
- To read problem let click red number on table
Sugget:
- Problem is just an atomic mass calculation based on a given formula
Code:
#include<bits/stdc++.h>
using namespace std;
int t;
string s;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> t;
while(t--){
cin >> s;
float sum= 0;
for(int i=0; s[i]; i++){
float alpha= -1;
if (s[i]=='C') alpha= 12.01;
if (s[i]=='H') alpha= 1.008;
if (s[i]=='O') alpha= 16;
if (s[i]=='N') alpha= 14.01;
if (alpha != -1){
string x="";
int j;
for(j=i+1; s[j] && ('0'<= s[j] && s[j] <= '9'); j++)
x += s[j];
int n = (x=="" ? 1 : stoi(x));
sum += alpha*n;
}
}
cout<<fixed<<setprecision(3)<<sum<<"\n";
}
}
No comments:
Post a Comment