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

我的想法。

Posted by Blueve at 2011-07-25 13:17:16 on Problem 2876
0是
-
1是
- -
其实就是0的部分加上0部分的长度个空格再加一个0部分
所以2就是
- -加上三个空格再加上一个自己,最后就是
- -   - -
于是可以避免使用递归了。
C++的话用标准库代码很容易看,但时间稍长16ms,不用标准库应该就可以0ms了
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int N, i;
	string p, s;
	while(cin >> N)
	{
		p = '-';
		for(i = 0; i < N; ++i)
		{
			s.assign(p.size(), ' ');
			p += s + p;
		}
		cout << p << endl;
	}
	return 0;
}

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