-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsplit7.cpp
53 lines (44 loc) · 1.42 KB
/
split7.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Contributed by Arash Partow (http://www.partow.net/)
// Requires StrTk (http://www.partow.net/programming/strtk/index.html)
#include <iostream>
#include <string>
#include <ctime>
#include <vector>
#include "strtk.hpp"
int main()
{
std::string input_line;
typedef std::pair<const char *, const char *> StrLimits;
std::vector<StrLimits> spline;
long count = 0;
int sec, lps;
time_t start = time(NULL);
std::cin.sync_with_stdio(false); //disable synchronous IO
const strtk::single_delimiter_predicate<std::string::value_type> delimiter(' ');
std::size_t numWords = 0;
std::size_t numChars = 0;
while(std::cin)
{
std::getline(std::cin, input_line);
spline.resize(100);
std::size_t numFields = strtk::split(delimiter,
input_line,
spline.begin());
spline.resize(numFields);
numWords += numFields;
for (std::vector<StrLimits>::const_iterator iter = spline.begin(); iter != spline.end(); ++iter)
numChars += iter->second - iter->first;
count++;
};
count--; //subtract for final over-read
sec = (int) time(NULL) - start;
std::cerr << "C++ : Saw " << count << " lines (" << numWords << " words/" << numChars << " chars) in " << sec << " seconds." ;
if (sec > 0)
{
lps = count / sec;
std::cerr << " Crunch speed: " << lps << std::endl;
}
else
std::cerr << std::endl;
return 0;
}