Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用String也可以过,不过最好把答案一次性输出,用ostringstream [有代码慎入]int cmp(const string & a, const string & b) { if (a.length() > b.length()) return cmp(b, a); for (int i = 0; i < a.length(); i ++) { if (a[i] != b[i]) return i; } return a.length(); } int main() { string s[2] = {"", ""}; ostringstream output; int k = 0, curr = 0; while (cin >> s[++k % 2] && s[k % 2] != ".") { int len = cmp(s[k % 2], s[(k + 1) % 2]); if (len == 0) { curr = 0; output << s[k % 2] << endl; } else { if (curr + 1 <= len) curr ++; else curr = len; output << string(curr, ' ') << s[k % 2] << endl; } } cout << output.str() << endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator