Text processing/Max licenses in use: Difference between revisions

→‎{{header|C++}}: Added correct solution
m (Remove "incomplete" message)
(→‎{{header|C++}}: Added correct solution)
Line 301:
 
=={{header|C++}}==
<lang cpp>#include <iostreamfstream>
{{incomplete|C++|The maximum occurs at more than one time.}}
#include <fstreamiostream>
{{libheader|Boost}}
#include <iterator>
 
<lang cpp>#include <iostream>
#include <boost/algorithm/string.hpp>
#include <string>
#include <fstream>
#include <vector>
 
int main( int argc, char * argv[ ] ) {
{
if ( argc != 2 ) {
const char logfilename[] = "mlijobs.txt";
std::cout << "Error: syntax: ./licenseout <filename of data file>!\n " ;
std::ifstream logfile(logfilename);
return 1 ;
 
}
if ( infile!logfile.is_open( ) ) {
std::ifstream infile ( argv[ 1 ] , std::ios::in ) ;
{
//nextLine holds the next line of the text file , maxTime the time with
std::coutcerr << "CouldError not openopening: " << argv[ 1 ]logfilename << " !\n" ;
//most licenses out , timeOut the respective time entry in a file line
std::string nextLine , maxTime , timeOutreturn -1;
}
//count holds the number of licenses out at any time , maxcount the maximum
 
//number
int countlicense = 0 , maxcountmax_license = 0 ;
std::vector<std::string> lineElements max_timestamp; //for the words of a text line
 
if ( infile.is_open( ) ) {
for (std::string logline; std::getline(logfile, logline); )
while ( infile ) {
} {
getline( infile , nextLine ) ;
std::string action(logline.substr(8,3));
boost::split( lineElements, nextLine , boost::is_any_of( " " ) ) ;
 
if ( lineElements[ 1 ] == "OUT" ) {
if (action == "OUT")
count++ ;
if ( argc != 2 ) {
timeOut = lineElements[ 3 ] ;
if (++license >= max_license)
}
if ( lineElements[ 1 ] == "IN" ) {
if (license > max_license)
count-- ;
if ( count > maxcount ) {
max_license = license;
maxcount = count ;
max_timestamp.clear();
maxTime = timeOut ;
}
}
max_timestamp.push_back(logline.substr(14, 19));
lineElements.clear( ) ;
}
infile.close( ) ;}
else if (action == "IN ")
std::cout << "The maximum number of licenses out is " << maxcount <<
" at " << maxTime << " !\n" ;{
return 0 --license;
} else { }
}
std::cout << "Could not open " << argv[ 1 ] << " !\n" ;
 
return 1 ;
std::cout << "License count at log end: " << license
}
<< "\nMaximum simultaneous license: " << max_license
}
<< "\nMaximum license time(s):\n";
</lang>
 
<pre>Output:
std::copy(max_timestamp.begin(), max_timestamp.end(),
The maximum number of licenses out is 99 at 2008/10/03_08:39:34 !
std::ostream_iterator<std::string>(std::cout, "\n"));
</pre>
}</lang>
Output:<pre>License count at log end: 0
Maximum simultaneous licenses: 99
Maximum license time(s):
2008/10/03_08:39:34
2008/10/03_08:40:40</pre>
 
=={{header|C sharp|C#}}==