Redian新闻
>
爱小动物的人就是不冷!
avatar
爱小动物的人就是不冷!# pets - 心有所宠
y*e
1
题意我有点迷糊,不明白为啥public int read(char[] buf, int n)给出说buf是
destination buffer,
但看了答案之后半懂不懂的写了一个c++的,通过了,是这样的
int read(char *buf, int n) {
bool eof=false;
int readBytes=0;
while(!eof && readBytes<=n)
{
int sz=read4(buf);
if(sz<4) eof=true;
int bytes = min(n - readBytes, sz);
readBytes+=bytes;
buf+=bytes;
}
return readBytes;
}
大概的思路就是每次用read4从buf里读,然后指针往后挪,一直挪到eof或者n reached
,这里的buf应该和我理解的一样就是要读的source file。
但java的答案我就很糊涂了,因为没有那个可以一直指向char array头的指针,于是有
了一个char array叫buffer
public int read(char[] buf, int n) {
char[] buffer = new char[4];
int readBytes = 0;
boolean eof = false;
while(!eof && readBytes < n){
int sz = read4(buffer);
if(sz < 4){
eof = true;
}
int bytes = Math.min(n - readBytes, sz);
System.arraycopy(buffer, 0, buf, readBytes, bytes);
readBytes += bytes;
}
return readBytes;
}
我的问题是这个buffer怎么从buf里copy数据的? 不是应该从buf里拷贝到buffer,一次
烤4个char,为啥source和dest我理解错了?一开始的时候我们initialize一个空的
buffer,为啥int sz = read4(buffer)就能populate buffer?如果说buffer不是
source而是destination,那source file又是哪个?
头疼!心塞!
avatar
l*n
2
昨天半夜Del Mar Ave上I-10 West,刚进ramp就感觉后面闪光被拍照了,继续往前开发
现进了fastrak道。平时不怎么在这边走,网上搜了才知道HOV道改成收费道了。有没有
大牛知道这个要罚多少?怎么样能减免一些?
多谢
这个fastrak不知道是搞什么名堂,让有钱人上下班更舒爽?
avatar
l*8
3
......
avatar
r*e
4
我怎么感觉你这个解法有问题。
int sz = read4(buf);
这行跑完了,如果buf不变,那么以后每次写字符都是在前4个字符上重复操作。
avatar
Y*r
5
HOV lanes are still free for carpoolers, fastrak only gives more flexibility
to non HOV drivers who want to take advantage of the HOV traffic by paying
some fee. Just wait for your ticket in the mail and pay it. Should be less
than 100 bucks.

【在 l****n 的大作中提到】
: 昨天半夜Del Mar Ave上I-10 West,刚进ramp就感觉后面闪光被拍照了,继续往前开发
: 现进了fastrak道。平时不怎么在这边走,网上搜了才知道HOV道改成收费道了。有没有
: 大牛知道这个要罚多少?怎么样能减免一些?
: 多谢
: 这个fastrak不知道是搞什么名堂,让有钱人上下班更舒爽?

avatar
n*l
6
这要是换个角度蹲下来拍,一定更震撼

【在 l******8 的大作中提到】
: ......
avatar
y*e
7
buf+=bytes;
buf在往后挪啊。。。。

【在 r*******e 的大作中提到】
: 我怎么感觉你这个解法有问题。
: int sz = read4(buf);
: 这行跑完了,如果buf不变,那么以后每次写字符都是在前4个字符上重复操作。

avatar
l*u
8
是变成只是fastrak了还是fastrack+carpool了?

flexibility
paying
开发
没有

【在 Y***r 的大作中提到】
: HOV lanes are still free for carpoolers, fastrak only gives more flexibility
: to non HOV drivers who want to take advantage of the HOV traffic by paying
: some fee. Just wait for your ticket in the mail and pay it. Should be less
: than 100 bucks.

avatar
c*s
9
腿和脚的姿势,很有难度!
avatar
r*e
10
C++ 不熟,没注意到这么强悍的写法。
Java的解法实际上是个BufferedReader,通过调用read4 每次读取一定量数据,扔到一
块缓冲区,然后reader自己被调用时,如果缓冲区中数据足够了,就直接拷贝,否则继
续调用read4
所以java解法中的char array 其实就是个缓冲区,如此而已。
比较流行的形式是read4k,为何是4k的原因跟硬盘的存储格式有关,4k似乎正好是一个
簇,每次读硬盘至少要读一个簇。

【在 y*****e 的大作中提到】
: buf+=bytes;
: buf在往后挪啊。。。。

avatar
i*s
11
free for carpoller, 但是好像要必须
买那个扣钱的东西。 没那个好像carpool也不能上。

flexibility
paying

【在 Y***r 的大作中提到】
: HOV lanes are still free for carpoolers, fastrak only gives more flexibility
: to non HOV drivers who want to take advantage of the HOV traffic by paying
: some fee. Just wait for your ticket in the mail and pay it. Should be less
: than 100 bucks.

avatar
B*y
12
阅!转发宋嫂同乐…

【在 l******8 的大作中提到】
: ......
avatar
r*e
13
buffer是缓冲,调用read4的时候往buffer里面写
read的时候,用arraycopy 从buffer往buf里面写。

【在 y*****e 的大作中提到】
: 题意我有点迷糊,不明白为啥public int read(char[] buf, int n)给出说buf是
: destination buffer,
: 但看了答案之后半懂不懂的写了一个c++的,通过了,是这样的
: int read(char *buf, int n) {
: bool eof=false;
: int readBytes=0;
: while(!eof && readBytes<=n)
: {
: int sz=read4(buf);
: if(sz<4) eof=true;

avatar
m*u
14
昨天正好听到1300广播里说到这个10号收费道,说如果被拍照会寄来一个帐单金额很小
,大概几块钱,你付掉就好了,如果不付就会一直累计加倍上去。。。。你收到帐单再
上来汇报一下。

【在 l****n 的大作中提到】
: 昨天半夜Del Mar Ave上I-10 West,刚进ramp就感觉后面闪光被拍照了,继续往前开发
: 现进了fastrak道。平时不怎么在这边走,网上搜了才知道HOV道改成收费道了。有没有
: 大牛知道这个要罚多少?怎么样能减免一些?
: 多谢
: 这个fastrak不知道是搞什么名堂,让有钱人上下班更舒爽?

avatar
l*8
15
不怕.
前天晚上照的.

【在 B**********y 的大作中提到】
: 阅!转发宋嫂同乐…
avatar
f*c
16
应该buf是destination. buffer是缓冲,暂时存储从read4读取的数据,然后System.
arraycopy那一行是把buffer里面的数据copy到buf里面。

【在 y*****e 的大作中提到】
: 题意我有点迷糊,不明白为啥public int read(char[] buf, int n)给出说buf是
: destination buffer,
: 但看了答案之后半懂不懂的写了一个c++的,通过了,是这样的
: int read(char *buf, int n) {
: bool eof=false;
: int readBytes=0;
: while(!eof && readBytes<=n)
: {
: int sz=read4(buf);
: if(sz<4) eof=true;

avatar
y*z
17
You could either wait for the bill or go get a Fastrack transponder from AAA
, add the vehicle plate for this violation to your account when registering
online and enter an effective date which is earlier than yesterday's date.

【在 l****n 的大作中提到】
: 昨天半夜Del Mar Ave上I-10 West,刚进ramp就感觉后面闪光被拍照了,继续往前开发
: 现进了fastrak道。平时不怎么在这边走,网上搜了才知道HOV道改成收费道了。有没有
: 大牛知道这个要罚多少?怎么样能减免一些?
: 多谢
: 这个fastrak不知道是搞什么名堂,让有钱人上下班更舒爽?

avatar
l*8
18
不敢. 她爹在我前面正在交钱.

【在 n***l 的大作中提到】
: 这要是换个角度蹲下来拍,一定更震撼
avatar
y*e
19
既然是一直往buffer里面写,那是从哪里读的?我就很奇怪这个method signature里竟
然没有source file?

【在 r*******e 的大作中提到】
: buffer是缓冲,调用read4的时候往buffer里面写
: read的时候,用arraycopy 从buffer往buf里面写。

avatar
y*z
20
嗯,我老板上个月收到一张,$0.80,我们大家还笑了一轮居然有这么少金额的账单,来回
邮资加起来都比它贵了。

【在 m*****u 的大作中提到】
: 昨天正好听到1300广播里说到这个10号收费道,说如果被拍照会寄来一个帐单金额很小
: ,大概几块钱,你付掉就好了,如果不付就会一直累计加倍上去。。。。你收到帐单再
: 上来汇报一下。

avatar
Y*a
21

你应该挑唆你儿子去拍。呵呵
对了,问你一下,从芝加哥往西南开车,怎么个开法到沙漠最快?

【在 l******8 的大作中提到】
: 不敢. 她爹在我前面正在交钱.
avatar
r*e
22
src 在read4里面。

【在 y*****e 的大作中提到】
: 既然是一直往buffer里面写,那是从哪里读的?我就很奇怪这个method signature里竟
: 然没有source file?

avatar
s*g
23
--best answer

AAA
registering

【在 y**z 的大作中提到】
: You could either wait for the bill or go get a Fastrack transponder from AAA
: , add the vehicle plate for this violation to your account when registering
: online and enter an effective date which is earlier than yesterday's date.

avatar
l*8
24
一般都是砂石。 和你想象的差很远。
沙漠在墨西哥边界不远处。

【在 Y****a 的大作中提到】
:
: 你应该挑唆你儿子去拍。呵呵
: 对了,问你一下,从芝加哥往西南开车,怎么个开法到沙漠最快?

avatar
y*e
25
明白了,谢谢加菲!

【在 r*******e 的大作中提到】
: src 在read4里面。
avatar
z*n
26
干脆bill by plate得了,佛州就可以

【在 y**z 的大作中提到】
: 嗯,我老板上个月收到一张,$0.80,我们大家还笑了一轮居然有这么少金额的账单,来回
: 邮资加起来都比它贵了。

avatar
Y*a
27

给个地点吧。 我对那边不熟。如果你从芝加哥开,会开到哪里?

【在 l******8 的大作中提到】
: 一般都是砂石。 和你想象的差很远。
: 沙漠在墨西哥边界不远处。

avatar
y*e
28
明白了,谢谢左左!

【在 f********c 的大作中提到】
: 应该buf是destination. buffer是缓冲,暂时存储从read4读取的数据,然后System.
: arraycopy那一行是把buffer里面的数据copy到buf里面。

avatar
Y*r
29
91 fastrak就是bill by plate.前提是要在网上把plate#和fastrak# link在一起。用
了5年了,就是靠照相拍照收费的。

【在 z*********n 的大作中提到】
: 干脆bill by plate得了,佛州就可以
avatar
r*a
30
当然是来我这

★ 发自iPhone App: ChineseWeb 8.1

【在 Y****a 的大作中提到】
:
: 给个地点吧。 我对那边不熟。如果你从芝加哥开,会开到哪里?

avatar
t*0
31
11月30日走了很短一咕噜,上月接到账单,90美分。
avatar
Y*a
32

你包吃喝玩乐的一个星期话,可以考虑去你们那个冰窖。

【在 r*****a 的大作中提到】
: 当然是来我这
:
: ★ 发自iPhone App: ChineseWeb 8.1

avatar
s*g
33
It does. You just need one transponder and an account and register all your
vehicles. But you cannot get the free carpool rate w/o the transponder.

【在 z*********n 的大作中提到】
: 干脆bill by plate得了,佛州就可以
avatar
r*a
34
哈哈,没问题

★ 发自iPhone App: ChineseWeb 8.1

【在 Y****a 的大作中提到】
:
: 你包吃喝玩乐的一个星期话,可以考虑去你们那个冰窖。

avatar
d*u
35
现在是刚开始,所以罚款只是toll fee。估计过一阵就该是罚款加toll fee了,这个罚
款好像是50多吧
avatar
l*8
36
Google "white desert national park"
或LA和Phoenix之间的8号路上.

【在 Y****a 的大作中提到】
:
: 你包吃喝玩乐的一个星期话,可以考虑去你们那个冰窖。

avatar
l*8
37
从这个角度?

【在 Y****a 的大作中提到】
:
: 你包吃喝玩乐的一个星期话,可以考虑去你们那个冰窖。

avatar
Y*a
38

你是让我去看狗自己去赌城玩吧

【在 r*****a 的大作中提到】
: 哈哈,没问题
:
: ★ 发自iPhone App: ChineseWeb 8.1

avatar
r*a
39
哎,被识破啦
我亲家母到底去不去啊,要不J爹你也去吧,可以一起去沙漠飙车

【在 Y****a 的大作中提到】
:
: 你是让我去看狗自己去赌城玩吧

avatar
Y*a
40

你们开车去???

【在 r*****a 的大作中提到】
: 哎,被识破啦
: 我亲家母到底去不去啊,要不J爹你也去吧,可以一起去沙漠飙车

avatar
B*y
41
哈哈!你们那天气真逗,可以这样穿衣服。按照我妈的说法:上面蒸年糕,下面卖凉粉。

【在 l******8 的大作中提到】
: 不怕.
: 前天晚上照的.

avatar
r*a
42
不开,不过LD有去沙漠飙车的想法

【在 Y****a 的大作中提到】
:
: 你们开车去???

avatar
Y*a
43

那没有意思。

【在 r*****a 的大作中提到】
: 不开,不过LD有去沙漠飙车的想法
avatar
r*a
44
我俩开车旅行的极限是去芝加哥。。。。

【在 Y****a 的大作中提到】
:
: 那没有意思。

avatar
l*8
45
我在海水边的沙滩上班飙过车.

【在 r*****a 的大作中提到】
: 不开,不过LD有去沙漠飙车的想法
avatar
r*a
46
你这个错别字啊,还以为你是穿比基尼的救生员

★ 发自iPhone App: ChineseWeb 8.1

【在 l******8 的大作中提到】
: 我在海水边的沙滩上班飙过车.
avatar
p*y
47
我有种预感,老宋又要发女人应该怎样怎样的长文了。。。
avatar
l*8
48
我现在最想发的帖子是大骂us airways.
目前在SFO机场。

【在 p*******y 的大作中提到】
: 我有种预感,老宋又要发女人应该怎样怎样的长文了。。。
avatar
l*8
49
中国民航除了机长和乘务长外都挺漂亮的。

【在 p*******y 的大作中提到】
: 我有种预感,老宋又要发女人应该怎样怎样的长文了。。。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。