Commit b56b0fa9 by Xinfu L

Homework-15

parent 40df8d85
#include<iostream>
#include<string>
#include<regex>
using namespace std;
int main() {
/*
string text("How now, brown cow");
cout << boolalpha;
regex ow("ow");
regex Hstarw("H.*?w");
cout << regex_match(text, ow) << endl;
cout << regex_match(text, Hstarw) << endl;
cout << regex_search(text, ow) << endl;
smatch results;
regex_search(text, results, Hstarw);
copy(results.begin(), results.end(), ostream_iterator<string>(cout, "\n"));
*/
string seq = "Here are some numbers: 1.23, 4, 5.6, 7.89";
regex rgx("(\\d)\\.(\\d*)");
smatch r;
while (regex_search (seq, r, rgx)) {
cout << r[1] << " is before the decimal and " << r[2] << " is after the decimal" << endl;
seq = r.suffix().str();
}
return 0;
}
\ No newline at end of file
#include<iostream>
#include<fstream>
#include<string>
#include<regex>
using namespace std;
int main() {
ifstream inp("hurdat_atlantic_1851-2011.txt");
int c = 0;
double tot = -1;
regex rgx("(\\d{2})/(\\d{2})/(\\d{4})");
smatch r;
string R = "";
for(string line; getline(inp, line);) {
if(regex_search(line, r, rgx)) {
if(r[3] != R) {
if(tot != -1) {
cout << c << ' ' << R << ' ' << tot << endl;
}
c++;
R = r[3];
tot = 0;
}
}
else {
if(line.back() == '*') {
tot += (stoi(line.substr(20, 22)) + stoi(line.substr(37, 39)) + stoi(line.substr(54, 56)) + stoi(line.substr(71, 73)))/4.0;
break;
}
}
}
cout << c << ' ' << R << ' ' << tot << endl;
return 0;
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment