Click
Here to go back to the homepage.
Pervasive Heart Monitor Solution:
#include <bits/stdc++.h>
using namespace std;
const regex FLOAT_REGEX("\\s*\\d*\\.?\\d*\\s*");
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
string line;
while(getline (cin, line)){
string name;
double heart_rate_total = 0;
int heart_rate_count = 0;
string word;
stringstream lineStream(line);
while(getline(lineStream, word, ' ')){
smatch pieces_match;
if (regex_match(word, pieces_match, FLOAT_REGEX)) {
heart_rate_total += stof(word);
heart_rate_count++;
}
else{
if(name.length()){
name.append(" " + word);
}
else{
name.append(word);
}
}
}
cout << heart_rate_total / heart_rate_count << " " << name << endl;
}
return 0;
}