Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用String也可以过,不过最好把答案一次性输出,用ostringstream [有代码慎入]

Posted by sunny_baby at 2013-05-21 09:39:59 on Problem 1750
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator