Redian新闻
>
网上买的莴笋种子第二年就失效了?
avatar
网上买的莴笋种子第二年就失效了?# gardening - 拈花惹草
i*e
1
这题大家写写看,虽然没什么算法,但是很考基本功。
另外,这是一道很好的面试题。因为题意可以很含糊,但是里边有很多细节需要搞清楚
,设计输入和输出。还有 corner cases 也有,很容易没考虑周全。
题目参考以下链接:
http://www.cs.rpi.edu//academics/courses/fall09/ds/hw/01_text_j
我对题目的理解,简短的述说:
"Text Justification"
Given an array of words and a length L, format the text such that each line
has exactly L characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words
as you can in each line. Pad extra spaces ' ' when necessary so that each
line has exactly L characters.
Extra spaces between words should be distributed as evenly as possible. If
the number of spaces on a line do not divide evenly between words, the empty
slots on the left will be assigned more spaces than the slots on the right.
For the last line of text, it should be left justified and no extra space is
inserted between words.
For example,
words: ["This", "is", "an", "example", "of", "text", "justification."]
L: 16.
Return the formatted lines as:
[
"This is an",
"example of text",
"justification. "
]
Note: Each word is guaranteed not to exceed L in length.
这道题可以在 OJ 测试程序:
http://www.leetcode.com/onlinejudge
avatar
p*m
2
TSC 25号接受的PP, 28号的ND,到现在没有动静正常吗,,求bless
avatar
x*m
3
去年在http://www.agrohaitai.com/rootstem/celtuce/celtuce.htm买的莴笋种子,当时种的时候发芽率很好。家里地小没有种完,今年又翻出来种,下地一个月了居然一颗苗也没有发出来。是这种种子就是这样的吗?我在8/9区交界的地方
avatar
l*8
4
标点符号怎么算?
avatar
m*y
5
should be ok. bless.

【在 p*****m 的大作中提到】
: TSC 25号接受的PP, 28号的ND,到现在没有动静正常吗,,求bless
avatar
i*o
6
现在能种莴笋吗?

★ 发自iPhone App: ChineseWeb 8.6

【在 x****m 的大作中提到】
: 去年在http://www.agrohaitai.com/rootstem/celtuce/celtuce.htm买的莴笋种子,当时种的时候发芽率很好。家里地小没有种完,今年又翻出来种,下地一个月了居然一颗苗也没有发出来。是这种种子就是这样的吗?我在8/9区交界的地方
avatar
l*8
7
标点符号算是上一个单词的一部分吗?
哦,输入已经分割好单词了,这里"justification." 是一个单词
words: ["This", "is", "an", "example", "of", "text", "justification."]
avatar
a*8
8
正常。现在PP比以前慢了点,可能PP人太多了。都要10-15个calendar days才approve.
你的也快到15天,应该很快approve了, don't worry
avatar
n*1
9
八区应该能种。只要不下雪,能过冬的

【在 i****o 的大作中提到】
: 现在能种莴笋吗?
:
: ★ 发自iPhone App: ChineseWeb 8.6

avatar
i*e
10
算。所有只要不含空格的字符都属于单词的一部分。

【在 l*********8 的大作中提到】
: 标点符号算是上一个单词的一部分吗?
: 哦,输入已经分割好单词了,这里"justification." 是一个单词
: words: ["This", "is", "an", "example", "of", "text", "justification."]

avatar
t*g
11
正常。
两周,加个周末,才批
avatar
g*e
12
我的莴笋种子放冰箱冷藏室两三年都没问题。
可以试一下湿纸巾低温(冰箱冷藏室)催芽一周再育苗。
avatar
l*8
13
全部是English text,没有wchar甚至更多字节的字符吧?
avatar
a*s
14
请教这里的ND是什么?

【在 p*****m 的大作中提到】
: TSC 25号接受的PP, 28号的ND,到现在没有动静正常吗,,求bless
avatar
y*8
15
会不会是种深了
莴笋不难发芽,我用去年的没有问题

去年在http://www.agrohaitai.com/rootstem/celtuce/celtuce.htm买的莴笋种子,当时种的时候发芽率很好。家里地小没有种完,今年又翻出来种,下地一个月了居然一颗苗也没有发出来。是这种种子就是这样的吗?我在8/9区交界的地方

【在 x****m 的大作中提到】
: 去年在http://www.agrohaitai.com/rootstem/celtuce/celtuce.htm买的莴笋种子,当时种的时候发芽率很好。家里地小没有种完,今年又翻出来种,下地一个月了居然一颗苗也没有发出来。是这种种子就是这样的吗?我在8/9区交界的地方
avatar
i*e
16
没有。全是 ascii 字符。

【在 l*********8 的大作中提到】
: 全部是English text,没有wchar甚至更多字节的字符吧?
avatar
p*m
17
Notice Date

【在 a**********s 的大作中提到】
: 请教这里的ND是什么?
avatar
L*1
18
放5年没有问题。
我一般每3年留一次种。
avatar
l*8
19
如果一行只能fit一个word呢,如何对齐?
for example,
{"Examples", "of", "long", "word."}, L= 10,
"Examples" should be aligned to the left or to the middle of the line?
avatar
j*a
20
same here!

【在 p*****m 的大作中提到】
: TSC 25号接受的PP, 28号的ND,到现在没有动静正常吗,,求bless
avatar
i*o
21
蓝星给俺的种子赶紧催催去,催出来就上来汇报

★ 发自iPhone App: ChineseWeb 8.6

【在 g***e 的大作中提到】
: 我的莴笋种子放冰箱冷藏室两三年都没问题。
: 可以试一下湿纸巾低温(冰箱冷藏室)催芽一周再育苗。

avatar
l*8
22
如果一行只能fit一个word呢,如何对齐?
for example,
{"Examples", "of", "long", "word."}, L= 10,
"Examples" should be aligned to the left or to the middle of the line?
avatar
a*s
23
Notice什么的?pp收到的notice?

【在 p*****m 的大作中提到】
: Notice Date
avatar
i*e
24
很好的问题,这是其中一个 corner case。
如果一行只能放一个字,就左边对齐吧。

【在 l*********8 的大作中提到】
: 如果一行只能fit一个word呢,如何对齐?
: for example,
: {"Examples", "of", "long", "word."}, L= 10,
: "Examples" should be aligned to the left or to the middle of the line?

avatar
y*o
25
正常吧。
你看看timeline里面就大概知道了,多数TSC 的PP都是在10天或者以内批的,你就这一
两天了。

【在 p*****m 的大作中提到】
: TSC 25号接受的PP, 28号的ND,到现在没有动静正常吗,,求bless
avatar
l*8
26
这个题目很容易出错啊。
我写在纸上的程序好几个bugs。
加上在电脑的调试修改的时间,我总共花了两个小时才让程序基本正确(还不敢保证百分百正确,可能需要更多的测试案例)。这么慢怎么面试啊?
下面是程序(测试程序就不贴了):
void JustifyOneLine(const vector & words, int L, int lineStart, int
& lineEnd, vector & blankNum)
{
blankNum.clear();
int lengthSum = words[lineStart].size();
for (lineEnd = lineStart+1; lineEnd < words.size() && lengthSum + 1 +
words[lineEnd].size() <= L; lineEnd++) {
lengthSum += 1 + words[lineEnd].size();
blankNum.push_back(1);
}
int rest = L-lengthSum;
if (blankNum.size() == 0) {
blankNum.push_back(rest);
} else {
int idx(0);
while (rest > 0) {
blankNum[idx++] += 1;
if (idx == blankNum.size())
idx = 0;
rest--;
}
blankNum.push_back(0);
}
}
void AppendLine(vector & output, const vector & words, int L
, int lineStart, int lineEnd, const vector & blankNum)
{
string line(L, ' ');
size_t pos = 0;
for (int i=lineStart; iline.replace(pos, words[i].size(), words[i]);
pos += (words[i].size() + blankNum[i-lineStart]);
}
output.push_back(line);
}
void RemoveEndingBlanks(vector & text)
{
if (text.empty())
return;
string & str = text[text.size()-1];
size_t found = str.find_last_not_of(" ");
if (found!=string::npos)
str.erase(found+1);
else {
str.clear(); // str is all whitespace
text.pop_back();
}
}
void JustifyText(const vector & words, int L, vector &
output)
{
output.clear();
if(words.size() == 0 || L <= 0)
return;
vector blankNum;
blankNum.reserve(L/2);
int lineStart(0), lineEnd(0);
while ( lineEnd < words.size() ) {
JustifyOneLine(words, L, lineStart, lineEnd,blankNum);
AppendLine(output, words, L, lineStart, lineEnd, blankNum);
lineStart = lineEnd;
}

RemoveEndingBlanks(output);
}
avatar
b*r
27
正常,建议别去催,不然弄急了,让你补材料,你不做声,他们就给你批了.
avatar
w*o
28
你的这个输出是什么?是 vector吗?
如果输出是 C-style string的话,每行的结尾还要加个'\n',就是说每行占用了 L+1空
间。
请解释一下。
谢谢!

line
words

【在 i**********e 的大作中提到】
: 这题大家写写看,虽然没什么算法,但是很考基本功。
: 另外,这是一道很好的面试题。因为题意可以很含糊,但是里边有很多细节需要搞清楚
: ,设计输入和输出。还有 corner cases 也有,很容易没考虑周全。
: 题目参考以下链接:
: http://www.cs.rpi.edu//academics/courses/fall09/ds/hw/01_text_j
: 我对题目的理解,简短的述说:
: "Text Justification"
: Given an array of words and a length L, format the text such that each line
: has exactly L characters and is fully (left and right) justified.
: You should pack your words in a greedy approach; that is, pack as many words

avatar
a*i
29
bless

【在 p*****m 的大作中提到】
: TSC 25号接受的PP, 28号的ND,到现在没有动静正常吗,,求bless
avatar
l*8
30
如果不是机器判题的话,我觉得这个无所谓吧。 关键是对齐的过程。

【在 w****o 的大作中提到】
: 你的这个输出是什么?是 vector吗?
: 如果输出是 C-style string的话,每行的结尾还要加个'\n',就是说每行占用了 L+1空
: 间。
: 请解释一下。
: 谢谢!
:
: line
: words

avatar
m*u
31
bless

【在 p*****m 的大作中提到】
: TSC 25号接受的PP, 28号的ND,到现在没有动静正常吗,,求bless
avatar
l*8
32
leetcode,谢谢推荐这个题目。
我发现OnlineJudge的答案有问题。
题目要求:
For the last line of text, it should be left justified and no extra space is
inserted between words.
但是OnlineJudge expected 的答案却是最后一行也有空格。

line
words

【在 i**********e 的大作中提到】
: 这题大家写写看,虽然没什么算法,但是很考基本功。
: 另外,这是一道很好的面试题。因为题意可以很含糊,但是里边有很多细节需要搞清楚
: ,设计输入和输出。还有 corner cases 也有,很容易没考虑周全。
: 题目参考以下链接:
: http://www.cs.rpi.edu//academics/courses/fall09/ds/hw/01_text_j
: 我对题目的理解,简短的述说:
: "Text Justification"
: Given an array of words and a length L, format the text such that each line
: has exactly L characters and is fully (left and right) justified.
: You should pack your words in a greedy approach; that is, pack as many words

avatar
l*8
33
不好意思,我看错了。
是不要在最后一行的单词之间插入空格, 我想成不要在末尾插入空格了。。。。

is

【在 l*********8 的大作中提到】
: leetcode,谢谢推荐这个题目。
: 我发现OnlineJudge的答案有问题。
: 题目要求:
: For the last line of text, it should be left justified and no extra space is
: inserted between words.
: 但是OnlineJudge expected 的答案却是最后一行也有空格。
:
: line
: words

avatar
i*e
34
那个是指 extra space,就是最后一行字与字之间一个空格隔开就好了,左边对齐。后
面的空格 padding 还是需要的,确保达到每行的长度 == L 的条件。

is

【在 l*********8 的大作中提到】
: leetcode,谢谢推荐这个题目。
: 我发现OnlineJudge的答案有问题。
: 题目要求:
: For the last line of text, it should be left justified and no extra space is
: inserted between words.
: 但是OnlineJudge expected 的答案却是最后一行也有空格。
:
: line
: words

avatar
l*8
35
把我题目看错的地方改了一下,通过online judge了。献丑再贴一次。 请大家指教。
(觉得我写得好慢啊。。。)
class Solution {
public:
vector fullJustify(vector &words, int L) {
vector output;
if(words.size() == 0 || L <= 0) {
output.push_back("");
return output;
}
vector blankNum;
blankNum.reserve(L/2);
int lineStart(0), lineEnd(0);
while ( lineEnd < words.size() ) {
JustifyOneLine(words, L, lineStart, lineEnd,blankNum);
AppendLine(output, words, L, lineStart, lineEnd, blankNum);
lineStart = lineEnd;
}

return output;
} // end of fullJustify

private:
void JustifyOneLine(const vector & words, int L, int
lineStart, int& lineEnd, vector & blankNum)
{
blankNum.clear();
int lengthSum = words[lineStart].size();
for (lineEnd = lineStart+1; lineEnd < words.size() && lengthSum + 1 +
words[lineEnd].size() <= L; lineEnd++) {
lengthSum += 1 + words[lineEnd].size();
blankNum.push_back(1);
}
int rest = L-lengthSum;
if (blankNum.size() == 0) {
blankNum.push_back(rest);
} else if (lineEnd < words.size()) {
int idx(0);
while (rest > 0) {
blankNum[idx++] += 1;
if (idx == blankNum.size())
idx = 0;
rest--;
}
blankNum.push_back(0);
}
} // end of JustifyOneLine
void AppendLine(vector & output, const vector & words, int
L, int lineStart, int lineEnd, const vector & blankNum)
{
string line(L, ' ');
size_t pos = 0;
for (int i=lineStart; iline.replace(pos, words[i].size(), words[i]);
pos += (words[i].size() + blankNum[i-lineStart]);
}
output.push_back(line);
}
};
avatar
l*8
36
谢谢回答。我之前把题目看错了。。

【在 i**********e 的大作中提到】
: 那个是指 extra space,就是最后一行字与字之间一个空格隔开就好了,左边对齐。后
: 面的空格 padding 还是需要的,确保达到每行的长度 == L 的条件。
:
: is

avatar
i*e
37
这题大家写写看,虽然没什么算法,但是很考基本功。
另外,这是一道很好的面试题。因为题意可以很含糊,但是里边有很多细节需要搞清楚
,设计输入和输出。还有 corner cases 也有,很容易没考虑周全。
题目参考以下链接:
http://www.cs.rpi.edu//academics/courses/fall09/ds/hw/01_text_j
我对题目的理解,简短的述说:
"Text Justification"
Given an array of words and a length L, format the text such that each line
has exactly L characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words
as you can in each line. Pad extra spaces ' ' when necessary so that each
line has exactly L characters.
Extra spaces between words should be distributed as evenly as possible. If
the number of spaces on a line do not divide evenly between words, the empty
slots on the left will be assigned more spaces than the slots on the right.
For the last line of text, it should be left justified and no extra space is
inserted between words.
For example,
words: ["This", "is", "an", "example", "of", "text", "justification."]
L: 16.
Return the formatted lines as:
[
"This is an",
"example of text",
"justification. "
]
Note: Each word is guaranteed not to exceed L in length.
这道题可以在 OJ 测试程序:
http://www.leetcode.com/onlinejudge
avatar
l*8
38
标点符号怎么算?
avatar
l*8
39
标点符号算是上一个单词的一部分吗?
哦,输入已经分割好单词了,这里"justification." 是一个单词
words: ["This", "is", "an", "example", "of", "text", "justification."]
avatar
i*e
40
算。所有只要不含空格的字符都属于单词的一部分。

【在 l*********8 的大作中提到】
: 标点符号算是上一个单词的一部分吗?
: 哦,输入已经分割好单词了,这里"justification." 是一个单词
: words: ["This", "is", "an", "example", "of", "text", "justification."]

avatar
l*8
41
全部是English text,没有wchar甚至更多字节的字符吧?
avatar
i*e
42
没有。全是 ascii 字符。

【在 l*********8 的大作中提到】
: 全部是English text,没有wchar甚至更多字节的字符吧?
avatar
l*8
43
如果一行只能fit一个word呢,如何对齐?
for example,
{"Examples", "of", "long", "word."}, L= 10,
"Examples" should be aligned to the left or to the middle of the line?
avatar
l*8
44
如果一行只能fit一个word呢,如何对齐?
for example,
{"Examples", "of", "long", "word."}, L= 10,
"Examples" should be aligned to the left or to the middle of the line?
avatar
i*e
45
很好的问题,这是其中一个 corner case。
如果一行只能放一个字,就左边对齐吧。

【在 l*********8 的大作中提到】
: 如果一行只能fit一个word呢,如何对齐?
: for example,
: {"Examples", "of", "long", "word."}, L= 10,
: "Examples" should be aligned to the left or to the middle of the line?

avatar
l*8
46
这个题目很容易出错啊。
我写在纸上的程序好几个bugs。
加上在电脑的调试修改的时间,我总共花了两个小时才让程序基本正确(还不敢保证百分百正确,可能需要更多的测试案例)。这么慢怎么面试啊?
下面是程序(测试程序就不贴了):
void JustifyOneLine(const vector & words, int L, int lineStart, int
& lineEnd, vector & blankNum)
{
blankNum.clear();
int lengthSum = words[lineStart].size();
for (lineEnd = lineStart+1; lineEnd < words.size() && lengthSum + 1 +
words[lineEnd].size() <= L; lineEnd++) {
lengthSum += 1 + words[lineEnd].size();
blankNum.push_back(1);
}
int rest = L-lengthSum;
if (blankNum.size() == 0) {
blankNum.push_back(rest);
} else {
int idx(0);
while (rest > 0) {
blankNum[idx++] += 1;
if (idx == blankNum.size())
idx = 0;
rest--;
}
blankNum.push_back(0);
}
}
void AppendLine(vector & output, const vector & words, int L
, int lineStart, int lineEnd, const vector & blankNum)
{
string line(L, ' ');
size_t pos = 0;
for (int i=lineStart; iline.replace(pos, words[i].size(), words[i]);
pos += (words[i].size() + blankNum[i-lineStart]);
}
output.push_back(line);
}
void RemoveEndingBlanks(vector & text)
{
if (text.empty())
return;
string & str = text[text.size()-1];
size_t found = str.find_last_not_of(" ");
if (found!=string::npos)
str.erase(found+1);
else {
str.clear(); // str is all whitespace
text.pop_back();
}
}
void JustifyText(const vector & words, int L, vector &
output)
{
output.clear();
if(words.size() == 0 || L <= 0)
return;
vector blankNum;
blankNum.reserve(L/2);
int lineStart(0), lineEnd(0);
while ( lineEnd < words.size() ) {
JustifyOneLine(words, L, lineStart, lineEnd,blankNum);
AppendLine(output, words, L, lineStart, lineEnd, blankNum);
lineStart = lineEnd;
}

RemoveEndingBlanks(output);
}
avatar
w*o
47
你的这个输出是什么?是 vector吗?
如果输出是 C-style string的话,每行的结尾还要加个'\n',就是说每行占用了 L+1空
间。
请解释一下。
谢谢!

line
words

【在 i**********e 的大作中提到】
: 这题大家写写看,虽然没什么算法,但是很考基本功。
: 另外,这是一道很好的面试题。因为题意可以很含糊,但是里边有很多细节需要搞清楚
: ,设计输入和输出。还有 corner cases 也有,很容易没考虑周全。
: 题目参考以下链接:
: http://www.cs.rpi.edu//academics/courses/fall09/ds/hw/01_text_j
: 我对题目的理解,简短的述说:
: "Text Justification"
: Given an array of words and a length L, format the text such that each line
: has exactly L characters and is fully (left and right) justified.
: You should pack your words in a greedy approach; that is, pack as many words

avatar
l*8
48
如果不是机器判题的话,我觉得这个无所谓吧。 关键是对齐的过程。

【在 w****o 的大作中提到】
: 你的这个输出是什么?是 vector吗?
: 如果输出是 C-style string的话,每行的结尾还要加个'\n',就是说每行占用了 L+1空
: 间。
: 请解释一下。
: 谢谢!
:
: line
: words

avatar
l*8
49
leetcode,谢谢推荐这个题目。
我发现OnlineJudge的答案有问题。
题目要求:
For the last line of text, it should be left justified and no extra space is
inserted between words.
但是OnlineJudge expected 的答案却是最后一行也有空格。

line
words

【在 i**********e 的大作中提到】
: 这题大家写写看,虽然没什么算法,但是很考基本功。
: 另外,这是一道很好的面试题。因为题意可以很含糊,但是里边有很多细节需要搞清楚
: ,设计输入和输出。还有 corner cases 也有,很容易没考虑周全。
: 题目参考以下链接:
: http://www.cs.rpi.edu//academics/courses/fall09/ds/hw/01_text_j
: 我对题目的理解,简短的述说:
: "Text Justification"
: Given an array of words and a length L, format the text such that each line
: has exactly L characters and is fully (left and right) justified.
: You should pack your words in a greedy approach; that is, pack as many words

avatar
l*8
50
不好意思,我看错了。
是不要在最后一行的单词之间插入空格, 我想成不要在末尾插入空格了。。。。

is

【在 l*********8 的大作中提到】
: leetcode,谢谢推荐这个题目。
: 我发现OnlineJudge的答案有问题。
: 题目要求:
: For the last line of text, it should be left justified and no extra space is
: inserted between words.
: 但是OnlineJudge expected 的答案却是最后一行也有空格。
:
: line
: words

avatar
i*e
51
那个是指 extra space,就是最后一行字与字之间一个空格隔开就好了,左边对齐。后
面的空格 padding 还是需要的,确保达到每行的长度 == L 的条件。

is

【在 l*********8 的大作中提到】
: leetcode,谢谢推荐这个题目。
: 我发现OnlineJudge的答案有问题。
: 题目要求:
: For the last line of text, it should be left justified and no extra space is
: inserted between words.
: 但是OnlineJudge expected 的答案却是最后一行也有空格。
:
: line
: words

avatar
l*8
52
把我题目看错的地方改了一下,通过online judge了。献丑再贴一次。 请大家指教。
(觉得我写得好慢啊。。。)
class Solution {
public:
vector fullJustify(vector &words, int L) {
vector output;
if(words.size() == 0 || L <= 0) {
output.push_back("");
return output;
}
vector blankNum;
blankNum.reserve(L/2);
int lineStart(0), lineEnd(0);
while ( lineEnd < words.size() ) {
JustifyOneLine(words, L, lineStart, lineEnd,blankNum);
AppendLine(output, words, L, lineStart, lineEnd, blankNum);
lineStart = lineEnd;
}

return output;
} // end of fullJustify

private:
void JustifyOneLine(const vector & words, int L, int
lineStart, int& lineEnd, vector & blankNum)
{
blankNum.clear();
int lengthSum = words[lineStart].size();
for (lineEnd = lineStart+1; lineEnd < words.size() && lengthSum + 1 +
words[lineEnd].size() <= L; lineEnd++) {
lengthSum += 1 + words[lineEnd].size();
blankNum.push_back(1);
}
int rest = L-lengthSum;
if (blankNum.size() == 0) {
blankNum.push_back(rest);
} else if (lineEnd < words.size()) {
int idx(0);
while (rest > 0) {
blankNum[idx++] += 1;
if (idx == blankNum.size())
idx = 0;
rest--;
}
blankNum.push_back(0);
}
} // end of JustifyOneLine
void AppendLine(vector & output, const vector & words, int
L, int lineStart, int lineEnd, const vector & blankNum)
{
string line(L, ' ');
size_t pos = 0;
for (int i=lineStart; iline.replace(pos, words[i].size(), words[i]);
pos += (words[i].size() + blankNum[i-lineStart]);
}
output.push_back(line);
}
};
avatar
l*8
53
谢谢回答。我之前把题目看错了。。

【在 i**********e 的大作中提到】
: 那个是指 extra space,就是最后一行字与字之间一个空格隔开就好了,左边对齐。后
: 面的空格 padding 还是需要的,确保达到每行的长度 == L 的条件。
:
: is

avatar
r*m
54
先计算可以放的最大单词数,然后在单词中插入空格输出行
public class AdjustText {
static List justifyText(String[] words, int L) {
List result = new ArrayList();

int i = 0;
while (i < words.length) {
List lineWords = new ArrayList();
int curLen = 0;
do {
lineWords.add(words[i]);
curLen += words[i].length() + 1;
i++;
} while (i
result.add(justifyLine(lineWords, L - curLen + 1, i==words.
length, L));
}
return result;
}

static private String justifyLine(List lineWords, int
extralSpace, boolean b, int L) {
StringBuffer line = new StringBuffer();
if (b || lineWords.size() == 1) {
for (String w : lineWords) {
line.append(w);
line.append(" ");
}
line.deleteCharAt(line.length() - 1);
for (int i = 0; i < extralSpace; i++) {
line.append(" ");
}
return line.toString();
}

String nSpace = " ";
for (int i = 0; i < extralSpace / (lineWords.size() - 1); i++) {
nSpace += " ";
}

int mSpace = extralSpace % (lineWords.size() - 1);

for (int i = 0; i < lineWords.size(); i++) {
line.append(lineWords.get(i));
if (i < lineWords.size() - 1) {
line.append(nSpace);
if (i < mSpace) {
line.append(" ");
}
}
}

return line.toString();

}
public static void main(String[] args) {
String [] words = {"a","b","c","d","e"};
//{"This", "is", "an", "example", "of", "text", "justification."
};
int L = 3;
for (String line : justifyText(words, L)) {
System.out.println(line);
}

}
}
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。