## Sunday, October 9, 2011

### SRM187

Level 1 Level 2 Level 3
Div 1 Level 1 Level 2 Level 3
Div 2 Level 1 Level 2 Level 3

## Tutorials:

### Solution

Using regular expressions.

### Source Code:

//Sun Oct  9 22:28:19 PDT 2011
public class Cyberline {
public String lastCyberword(String cyberline) {
cyberline = cyberline.replaceAll("-", "");
String[] str = cyberline.split("[^a-zA-Z0-9@]+");
return str[str.length - 1];
}

// <%:testing-code%>
}

### Source Code:

//2009/09/09 11:21:10
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class DNASingleMatcher
{
public:
int longestMatch(string s1, string s2)
{
int ret = 0;
for (int i=0; i<s1.size(); i++)
{
string s;
s.clear();
for (int j=i; j<s1.size(); j++)
{
s += s1[j];
if (s2.find(s) != string::npos)
ret = max(ret, (int)s.size());
}
}
return ret;
}
};

### Source Code:

//2009/08/10 22:13:59
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;

class OfficeParking
{
public:
int spacesUsed(vector <string> events)
{
int space = 0;
int mmax = 0;
for(int i=0; i<events.size(); i++)
{
stringstream s(events[i]);
string s1,s2;
s >> s1 >> s2;
if(s2.compare("arrives") == 0)
space ++;
else if(s2.compare("departs") == 0)
space --;
mmax = max(mmax, space);
}
return mmax;
}
};