int PermutationSum::add (int n) { SS ss; ss << n; ST st; st = ss.str(); sort(all(st)); cout << ss.str() << endl; int ret = 0; do { ret += atoi(st.c_str()); } while(next_permutation(all(st))); return ret; }
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; }