Exemplo n.º 1
0
inline ST escapeCStringTpl(const ST &ba)
{
    ST ret;
    ret.reserve(ba.length() * 2);
    for (int i = 0; i < ba.length(); ++i) {
        CT c = ba.at(i);
        switch (c) {
            case '\\': ret += "\\\\"; break;
            case '\a': ret += "\\a"; break;
            case '\b': ret += "\\b"; break;
            case '\f': ret += "\\f"; break;
            case '\n': ret += "\\n"; break;
            case '\r': ret += "\\r"; break;
            case '\t': ret += "\\t"; break;
            case '\v': ret += "\\v"; break;
            case '"': ret += "\\\""; break;
            default:
                if (c < 32 || c == 127) {
                    ret += '\\';
                    ret += '0' + (c >> 6);
                    ret += '0' + ((c >> 3) & 7);
                    ret += '0' + (c & 7);
                } else {
                    ret += c;
                }
        }
	  void f() {
		    if(s.length() == 0)
				return;
//		    cout << s << " ; ";
		    int idx = 0;
		    forn(i, s.length())
				if(s[i] > s[idx])
					  idx = i;
		    ret += s[idx];
		    if(idx < s.length()) {
		   	 s = s.substr(idx+1);
		   	 f();
		    }
	  }
Exemplo n.º 3
0
	vector <string> countDescendants(vector <string> parentData)
	{
		f = true;
		vector <string> ret, fail;
		ST tmp = "";
		tr(it, parentData)	tmp += *it;
		
		while(tmp.length() > 0)
		{
			int idx = tmp.find(' ');
			vs.pb(tmp.substr(0, idx));
			if(idx == string::npos)	break;
			tmp = tmp.substr(idx+1);
		}

		sort(all(vs));
		vs.resize(unique(all(vs)) - vs.begin());

		tr(it, vs)
		{
			int idx = it->find(',');
			ST ch = it->substr(0, idx), par = it->substr(idx+1);
			cnt[ch] = cnt[par] = 0;
			g[par].pb(ch);
		}