Sunday, October 9, 2011

SRM203

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

Tutorials:


Division One - Level Three:

Solution

Source Code:


Division One - Level Two:

Solution

Source Code:


Division One - Level One:

Solution

Source Code:


Sivision Two - Level Three:

Solution

Using regular expressions.
It could be updated as: "((http://)?www\\.|http://)([a-zA-Z0-9]+\\.)+(com|tv|info|edu|org)"; if continious punctures are not allowed.

Source Code:

//Sun Oct  9 23:09:33 PDT 2011
public class UnLinker {
    public String clean(String text) {
        String reg = "((http://)?www\\.|http://)([a-zA-Z0-9.]+)\\.+(com|tv|info|edu|org)";
        String[] str = text.split(reg, -2);
        String ret = str[0];
        for (int i = 1; i < str.length; i++) {
            ret += "OMIT" + i + str[i];
        }
        return ret;
    }
    // <%:testing-code%>
}
// Powered by [KawigiEdit] 2.0!


Division Two - Level Two:

Solution

Source Code:


Division Two - Level One:

Solution

Source Code:

//2009/08/13 03:07:27
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <set>

using namespace std;

class UserName
{
public:
    string newMember(vector <string> exi, string newName)
    {
        set<string> sset;
        set<string>::iterator it;
        for(int i=0; i<exi.size(); i++) sset.insert(exi[i]);
        int sz = sset.size();
        sset.insert(newName);
        if(sset.size() > sz) return newName;
        int num = 1;
        while(1)
        {
            stringstream ss;
            ss << num;
            string s(newName);
            s += ss.str();
            sset.insert(s);
            if(sset.size() > sz) return s;
            num ++;
        }
    }
};

No comments :