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

这题目用G++ IO超时 只能改C++了 早知道就不用类写了 附上代码,各位帮忙优化下吧

Posted by ych_tiger at 2008-03-17 20:53:27 on Problem 1750
#include <iostream>
#include <vector>
#include <iterator>
#include <cstring>
#include <string>

using namespace std;

const char spaces[12][13]={
		"", // 0
		" ", //1
		"  ", //2
		"   ", //3
		"    ", //4
		"     ", //5
		"      ", //6
		"       ", //7
		"        ", //8
		"         ", //9
		"          ", //10
		"           "//11	
};

class StrSequence : public vector< pair<string, int> > {
private:

	void call(iterator iter) {
		iterator next;
		pair<string, int> *p, *pnext;
		p = &(*iter);

		for (next = iter+1; next!=this->end(); next++) {
			
			pnext = &(*next);
			if ( p->second==pnext->second 
					&& p->first.size()>p->second && pnext->first.size()>p->second && pnext->first.at(p->second) == p->first.at(p->second) ) {

				pnext->second++;
			} else {
				
				break;
			}
			
		}
		return;
	}

	void print(pair<string, int> *p) {
		cout<<spaces[p->second]<<p->first<<endl;
	}

public:
	StrSequence() {
		;
	}

	void input(string *str) {
		pair<string, int> *p;
		p =new pair<string, int>(*str,0);
		this->push_back(*p);
		delete p;
	}

	void output() {
		for (iterator iter = this->begin(); iter!=this->end(); iter++) {
			print(&(*iter));
		}
	}

	void solve() {
		for (iterator iter = begin(); iter!=this->end(); iter++) {
			call(iter);
		}
	}

};

int main() {

	StrSequence ss;

	string str;
	char temp[20];
	while (gets(temp)) {
		str = temp;
		if(strlen(temp)==0) break;
		ss.input(&str);
	}
	ss.solve();
	ss.output();

	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