avatar
Editor的信很重要吗?# Immigration - 落地生根
a*e
1
我不知道这种情况怎么继续努力啦,只能看看别人的答案?我觉得自己的思路是对的啊,
。。。有人碰到类似情况吗?
Last executed input:
["My","momma","always","said,",""Life","was","like","a","box
","of","chocolates.","You","never","know","what","you're","gonna","get."],
12
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.
class Solution {
public:
vector fullJustify(vector &words, int L) {
int n = words.size();
vector res;
if (n == 0) return res;
string tmp = words[0];
int num = 0;//num of spaces in between words
int start = 0;
for (int i = 1; i{
while (tmp.length() + words[i].length() + 1{
tmp = tmp + ' ' + words[i];
num++;
i++;
}
if (i >= n) break;
//add empty space
if (tmp.length(){
int morespace = L - tmp.length();
int perspace = num == 0 ? morespace : morespace / num;
int extraspace = num == 0 ? 0 : morespace%num;
tmp.insert(words[start].length(), perspace + extraspace, ' ');
int pos = words[start].length() + perspace + extraspace+1;
for (int j = start + 1; j{
pos += words[j].length()+1;
tmp.insert(pos, perspace, ' ');
}
}
res.push_back(tmp);
tmp = words[i];
num = 0;
start = i;
}
res.push_back(tmp);
return res;
}
};
avatar
c*r
2
我的EB1B材料差不多准备好了,review 了20次,invitation email都在,可律师说需要
journal editor的信才好写petition letter,我倒是要到过,可是对方用自己的模板,
律师不喜欢。这种信真的很必要吗?平时邀请审稿的email加上杂志介绍还不够?
avatar
h*d
3
只有一个单词的行/最后一行的空格数不对
必须右边填满空格
avatar
d*i
4
应该还是挺有用的。这类信可以说明你是因为工作杰出被邀请审稿,和一般reviewer不
一样。

需要
板,

【在 c********r 的大作中提到】
: 我的EB1B材料差不多准备好了,review 了20次,invitation email都在,可律师说需要
: journal editor的信才好写petition letter,我倒是要到过,可是对方用自己的模板,
: 律师不喜欢。这种信真的很必要吗?平时邀请审稿的email加上杂志介绍还不够?

avatar
a*e
5
多谢。又是题没看清就开写了。。。。。。。
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.
这种题如果面试碰到,把题理解清楚都要花好久吧。。。。。。。。。有人真的在面试
的时候碰到类似的吗?面试官拿张纸给你还是口头描述?Text Justification 这个东
西我都是第一次听说,当然word里面老用。
avatar
g*u
6
很奇怪,我要了编辑推荐信,写的挺好,律师居然说不用。

【在 d******i 的大作中提到】
: 应该还是挺有用的。这类信可以说明你是因为工作杰出被邀请审稿,和一般reviewer不
: 一样。
:
: 需要
: 板,

avatar
h*d
7
真的有人面过 没做过只有祈祷不遇到了

right.

【在 a***e 的大作中提到】
: 多谢。又是题没看清就开写了。。。。。。。
: 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.
: 这种题如果面试碰到,把题理解清楚都要花好久吧。。。。。。。。。有人真的在面试
: 的时候碰到类似的吗?面试官拿张纸给你还是口头描述?Text Justification 这个东

avatar
h*l
8
律师太忙,找个事给你做着先。理解一下就好。另外,编辑信中最好提到:
1)期刊影响力如何大
2)读者群是什么人
3)选reviewer的标准
4)申请人(你)多牛多牛
Good luck
avatar
z*y
9
大概有三个问题:
1.
while (tmp.length() + words[i].length() + 1应该i2.
int pos = words[start].length() + perspace + extraspace+1;
我理解空格应该是均摊,比如4个词有5个空格,应该是2 2 1, 而不是 3 1 1
3.
最后一行要特殊处理,尾部加空格即可。
avatar
k*o
10
读者群越大越好(专业杂志能有多大呢除非是交叉学科的)?还是强调International?

【在 h*****l 的大作中提到】
: 律师太忙,找个事给你做着先。理解一下就好。另外,编辑信中最好提到:
: 1)期刊影响力如何大
: 2)读者群是什么人
: 3)选reviewer的标准
: 4)申请人(你)多牛多牛
: Good luck

avatar
a*e
11
多谢,是1的问题,改了后马上变成wrong answer 了。。呵呵
2. 我没理解对 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.

【在 z***y 的大作中提到】
: 大概有三个问题:
: 1.
: while (tmp.length() + words[i].length() + 1: 应该i: 2.
: int pos = words[start].length() + perspace + extraspace+1;
: 我理解空格应该是均摊,比如4个词有5个空格,应该是2 2 1, 而不是 3 1 1
: 3.
: 最后一行要特殊处理,尾部加空格即可。

avatar
h*l
12
现在期刊基本都上网,所以可以强调international,同时看看点击量和下载率什么,
全世界多少图书馆收藏什么的。
现在专业杂志读者群也很大,我记得想biochem这类3分的杂志也接近1M/year的下载量
avatar
a*e
13
又改写了,还是通不过,有大侠能看出明显错误吗?好奇那些面试官对这类题怎么知道
到底写对没?
8 / 24 test cases passed.
多谢。
Input:
["Listen","to","many,","speak","to","a","few."], 6


Output:
["Listen","to ","many, ","speak ","to a","few. "]


Expected:
["Listen","to ","many, ","speak ","to a","few. "]
class Solution {
public:
vector fullJustify(vector &words, int L) {
int n = words.size();
vector res;
if (n == 0) return res;
string tmp = words[0];
int num = 0;//num of spaces in between words
int start = 0;
for (int i = 1; i{
while (i{
tmp = tmp + ' ' + words[i];
num++;
i++;
}
if (i >= n) break;
//add empty space
if (tmp.length(){
int morespace = L - tmp.length();
int perspace = num == 0 ? morespace : morespace / num;
int extraspace = num == 0 ? 0 : morespace%num;
if (num==1) extraspace=0;

int pos =0;
int c=0;
for (int j = start; j{
pos += words[j].length();
if (c{
tmp.insert(pos, perspace+1, ' ');
pos+=perspace+1;
c++;
}
else
{
tmp.insert(pos, perspace, ' ');
}

}
}
res.push_back(tmp);
tmp = words[i];
num = 0;
start = i;
}
if (tmp.length(){
int morespace = L - tmp.length();
int perspace = num == 0 ? morespace : morespace / num;
int extraspace = num == 0 ? 0 : morespace%num;
tmp.insert(words[start].length(), perspace + extraspace, ' ');

}
res.push_back(tmp);
return res;
}
};
avatar
z*y
14
for (int j = start; j{
pos += words[j].length();
if (c{
tmp.insert(pos, perspace+1, ' ');
pos+=perspace+1;
c++;
}
else
{
tmp.insert(pos, perspace, ' ');
}

}
这一段,start是开始的下标,i-1是结束下标吧?每一次都会往当前word后面插入空格
,最后一次是不是往末尾多加了空格?
前面连接的时候已经加过一个空格,pos是不是改是+=word[j].length() + 1
else里面不需要更新pos?
if (tmp.length(){
int morespace = L - tmp.length();
int perspace = num == 0 ? morespace : morespace / num;
int extraspace = num == 0 ? 0 : morespace%num;
tmp.insert(words[start].length(), perspace + extraspace, ' ');

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