标签:acm
const int maxn = 1100; char s[maxn]; int n; vector<int> v; int main() { int T; RI(T); while (T--) { v.clear(); RS(s); n = strlen(s); int num = 0, sig = 0; REP(i, n) { if (s[i] == '*') sig++; else { v.push_back(i); num++; } } int ans = 0; int preadd = 0; if (!sig) { ans = 0; } else { if (num < sig + 1) { preadd = sig + 1 - num; ans += preadd; } int sig_num = 0; for (int i = 0; i < n; i++) { if (s[i] == '*') { sig_num++; if (preadd < sig_num + 1) { int sz = v.size(); int id = v[sz - 1]; v.pop_back(); swap(s[i], s[id]); sig_num--; preadd++; ans++; } } else preadd++; } if (s[n - 1] != '*') ans++; } printf("%d\n", ans); } return 0; }
标签:acm
原文地址:http://blog.csdn.net/wty__/article/details/40043837