Google Code Jam Ignore The Comment
总结
1. 本身不是太难, 难的是想到好的切入点
2. 所有的代码读入后再做处理
3. 以 '/' 作为分隔符, 作检查
代码
vector<int> nest; vector<range> del; nest.clear(); del.clear(); int pos = -1; for(int i = 0; i < text.size(); i ++) { if(text[i] == '/') { if(i > 0 && text[i-1] == '*') { if(nest.empty()) continue; if(pos == i-1) continue; // last used star int left = nest.back(); nest.pop_back(); if(nest.empty()) { range tn; tn.l = left; tn.r = i; del.push_back(tn); } } else if (i < text.size()-1 && text[i+1] == '*') { nest.push_back(i); pos = i+1; } } while(!del.empty()) { range td = del.back(); text.erase(td.l, td.r-td.l+1); del.pop_back(); } }