现在的位置: 首页 > 综合 > 正文

SRM 233 Div II Level One: JustifyText

2013年12月13日 ⁄ 综合 ⁄ 共 539字 ⁄ 字号 评论关闭

题目来源: http://community.topcoder.com/stat?c=problem_statement&pm=4017&rd=6532

代码如下:

#include <string>
#include <vector>


using namespace std;

/************** Program  Begin *********************/

class JustifyText {
public:
    vector <string> format(vector <string> text) {
	vector <string> res = text;
	int maxlen = 0;

	for (int i = 0; i < text.size(); i++) {
		if (text[i].size() > maxlen) {
			maxlen = text[i].size();
		}
	}

	for (int i = 0; i < text.size(); i++) {
		if (text[i].size() < maxlen) {
			for (int j = 0; j < maxlen - text[i].size(); j++) {
				res[i] = " " + res[i];
			}
		}
	}
	return res;
    }

};

/************** Program End ************************/

抱歉!评论已关闭.