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); }
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(); } }
bool process(ST file) { ifstream in1(file.c_str()); if(in1 == nullptr) return false; ST outfile = "ocf." + file; ofstream out1(outfile.c_str()); ST st; vs includes; while(getline(in1, st)) { if(st.size() >= 8 && st.substr(0, 8) == "#include") includes.pb(st); else out1 << st << endl; } out1.flush(); ST tmpfile = "sqae." + file; ST command = "cpp " + outfile + " > " + tmpfile; system(command.c_str()); int idx = file.find_first_of('.'); // ST name = file.substr(0, idx) + "_new.cpp"; ST name = file.substr(0, idx) + "_preprocessed.cpp"; ifstream in2(tmpfile.c_str()); // ofstream out2(("new_" + file).c_str()); ofstream out2(name.c_str()); bool isTypedef = false; // out2 << "//%%%%%%%%%%%%\n//%%%%lost%%%%\n//%%%%%%%%%%%%\n\n"; out2 << "//Name : Shinchan Nohara\n" "//Age : 5 years\n" "//Organisation : Kasukabe Defense Force\n\n"; for(auto &x: includes) out2 << x << endl; bool blankLine = false; while(getline(in2, st)) { if(st.size() >= 2 && st.substr(0, 2) == "# ") continue; if(blankLine && st == "") continue; blankLine = false; if(isTypedef && !(st.size() >= 7 && st.substr(0, 7) == "typedef")) out2 << endl; if(st.size() >= 7 && st.substr(0, 7) == "typedef") { isTypedef = true; out2 << endl; } if(st == "") blankLine = true; int i; for(i = 0; i < st.size() && st[i] == ' '; i++) out2 << "\t"; out2 << st.substr(i); } system(("rm " + tmpfile).c_str()); system(("rm " + outfile).c_str()); return true; }