Redian新闻
>
大熊初现身影, 哈哈哈哈
avatar
大熊初现身影, 哈哈哈哈# Stock
w*r
1
【 以下文字转载自 Notice 讨论区 】
发信人: deliver (自动发信系统), 信区:
标 题: winderwater 封 whks 在 ebiz 版
发信站: BBS 未名空间站自动发信系统 (Tue Sep 14 14:48:49 2010)
【此篇文章是由自动发信系统所张贴】
由于 whks 在 ebiz 版的 广告 行为,
被暂时取消在本版的发文权力 14 天。
版主:winderwater
Tue Sep 14 14:48:49 2010
avatar
f*4
2
FG以前都面过的题目,貌似出现概率不低。搜索+论坛考古之后实在没有研究出满意的
答案,
原题如下:
Given API:
int Read4096(char* buf);
It reads data from a file and records the position so that the next time
when it is called it reads the next 4k chars (or the rest of the file,
whichever is smaller) from the file.
The return is the number of chars read.
Todo: Use above API to Implement API
"int Read(char* buf, int n)" which reads any number of chars from the file.
有没有大牛甩个python解法
avatar
f*t
3
200MA touched, oh yeah.
avatar
T*u
4
说说思路?是不是搞一个x<4096,读ceiling(n/4096)次,扔出前n个,留下剩下的在x
,下次读的时候从x继续?
avatar
w*t
5
俺觉的是快到头了...
avatar
s*x
6
以前有人贴过,代码很简单,思路楼上的。
avatar
f*t
7
as long as bulls still resist, there would be no end...xoxoxo

【在 w*******t 的大作中提到】
: 俺觉的是快到头了...
avatar
p*i
9
这个faz啥的好像没涨太多啊.
avatar
q*c
10
这道题挺有意思,不难但是要考虑几种情况, 试了一下:
int Read(char* buf, int n)
{
int total = 0;
while(true) {
total += Read4096(buf);
if(total == n || total < 4096) { break; }
if(total > n) {
total = n; buf += total;
break;
}
}
return total;
}
avatar
w*t
11
这很正常...

【在 p**i 的大作中提到】
: 这个faz啥的好像没涨太多啊.
avatar
f*4
12

buf是Input param, buf += total显然有问题a

【在 q********c 的大作中提到】
: 这道题挺有意思,不难但是要考虑几种情况, 试了一下:
: int Read(char* buf, int n)
: {
: int total = 0;
: while(true) {
: total += Read4096(buf);
: if(total == n || total < 4096) { break; }
: if(total > n) {
: total = n; buf += total;
: break;

avatar
l*t
13
昨天cover早了吧?哭死哭死

【在 f*******t 的大作中提到】
: 200MA touched, oh yeah.
avatar
a*e
14
原来那个简洁版的代码在哪呀。。。。
avatar
f*t
15
co-cry, haha.....fortunately we did not bottom fish catch knife...
haha haha hahaha hahahaha

【在 l**t 的大作中提到】
: 昨天cover早了吧?哭死哭死
avatar
y*n
16
这个题是很容易把我这种文科生转行的打回原形的。还有一个UTF8啥的,也是类似。
avatar
l*t
17
今天捞了点,目前水面1米...

【在 f*******t 的大作中提到】
: co-cry, haha.....fortunately we did not bottom fish catch knife...
: haha haha hahaha hahahaha

avatar
p*y
18
read(buf,1)

total=""> n) {

【在 q********c 的大作中提到】
: 这道题挺有意思,不难但是要考虑几种情况, 试了一下:
: int Read(char* buf, int n)
: {
: int total = 0;
: while(true) {
: total += Read4096(buf);
: if(total == n || total < 4096) { break; }
: if(total > n) {
: total = n; buf += total;
: break;

avatar
f*t
19
well, take care. I am not interested in any trading by next Monday...xoxoxo

【在 l**t 的大作中提到】
: 今天捞了点,目前水面1米...
avatar
f*4
20
FG以前都面过的题目,貌似出现概率不低。搜索+论坛考古之后实在没有研究出满意的
答案,
原题如下:
Given API:
int Read4096(char* buf);
It reads data from a file and records the position so that the next time
when it is called it reads the next 4k chars (or the rest of the file,
whichever is smaller) from the file.
The return is the number of chars read.
Todo: Use above API to Implement API
"int Read(char* buf, int n)" which reads any number of chars from the file.
有没有大牛甩个python解法
avatar
l*t
21
just small chips, gamble for oe, prepare for death lol

xoxoxo

【在 f*******t 的大作中提到】
: well, take care. I am not interested in any trading by next Monday...xoxoxo
avatar
T*u
22
说说思路?是不是搞一个x<4096,读ceiling(n/4096)次,扔出前n个,留下剩下的在x
,下次读的时候从x继续?
avatar
f*t
23
against trend,what do you expect? lol

【在 l**t 的大作中提到】
: just small chips, gamble for oe, prepare for death lol
:
: xoxoxo

avatar
s*x
24
以前有人贴过,代码很简单,思路楼上的。
avatar
l*t
25
let's see...

【在 f*******t 的大作中提到】
: against trend,what do you expect? lol
avatar
f*t
27
still ok? you are obviously caught by the second leg.....but if you are not
daytrader, then I say nothing...xoxoxoxo

【在 l**t 的大作中提到】
: let's see...
avatar
q*c
28
这道题挺有意思,不难但是要考虑几种情况, 试了一下:
int Read(char* buf, int n)
{
int total = 0;
while(true) {
total += Read4096(buf);
if(total == n || total < 4096) { break; }
if(total > n) {
total = n; buf += total;
break;
}
}
return total;
}
avatar
l*t
29
I said it's gamble chips, from profits, alreasy ok

not

【在 f*******t 的大作中提到】
: still ok? you are obviously caught by the second leg.....but if you are not
: daytrader, then I say nothing...xoxoxoxo

avatar
f*4
30

buf是Input param, buf += total显然有问题a

【在 q********c 的大作中提到】
: 这道题挺有意思,不难但是要考虑几种情况, 试了一下:
: int Read(char* buf, int n)
: {
: int total = 0;
: while(true) {
: total += Read4096(buf);
: if(total == n || total < 4096) { break; }
: if(total > n) {
: total = n; buf += total;
: break;

avatar
a*e
31
原来那个简洁版的代码在哪呀。。。。
avatar
y*n
32
这个题是很容易把我这种文科生转行的打回原形的。还有一个UTF8啥的,也是类似。
avatar
p*y
33
read(buf,1)

total=""> n) {

【在 q********c 的大作中提到】
: 这道题挺有意思,不难但是要考虑几种情况, 试了一下:
: int Read(char* buf, int n)
: {
: int total = 0;
: while(true) {
: total += Read4096(buf);
: if(total == n || total < 4096) { break; }
: if(total > n) {
: total = n; buf += total;
: break;

avatar
L*1
34
求教这道题有java版本解法嘛?谢谢
avatar
r*e
35
有,看我的。
public class Solution extends Reader4k {
private int offset;
private int size;
private char[] buffer;
public Solution(){
offset=0;
size=0;
buffer = new char[4096];
}
/**
* @param buf Destination buffer
* @param n Maximum number of characters to read
* @return The number of characters read
*/
public int read(char[] target, int n) {
int readbytes=0,step=0;
boolean isEnd = false;

while(!isEnd&&readbytes//1. Check if invoking reader4k is needed && if the end of the
file is reached
if (size==0) {size=read4k(buffer); isEnd = size!=4096;}
//2. Calculate how many chars need to be copied
step = Math.min(size,n-readbytes);
//3. Copy
System.arraycopy(buffer,offset,target,readbytes,step);
//4. Incremet counters
readbytes+=step;
offset=(step+offset)%4096;
size-=step;
}
return readbytes;
}
}
avatar
r*e
36
发了

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