求C语言闪烁星空语句

Python017

求C语言闪烁星空语句,第1张

在C的文件夹下有个Demo程序,里面就含有你所要的代码

void

PutPixelDemo(void)

{

int

seed

=

1958

int

i,

x,

y,

h,

w,

color

struct

viewporttype

vp

MainWindow(

"PutPixel

/

GetPixel

Demonstration"

)

getviewsettings(

&vp

)

h

=

vp.bottom

-

vp.top

w

=

vp.right

-

vp.left

srand(

seed

)

/*

Restart

random

#

function

*/

for(

i=0

i<5000

++i

){

/*

Put

5000

pixels

on

screen

*/

x

=

1

+

random(

w

-

1

)

/*

Generate

a

random

location

*/

y

=

1

+

random(

h

-

1

)

color

=

random(

MaxColors

)

putpixel(

x,

y,

color

)

}

srand(

seed

)

/*

Restart

Random

#

at

same

#

*/

for(

i=0

i<5000

++i

){

/*

Take

the

5000

pixels

off

*/

x

=

1

+

random(

w

-

1

)

/*

Generate

a

random

location

*/

y

=

1

+

random(

h

-

1

)

color

=

getpixel(

x,

y

)

/*

Read

the

color

pixel

*/

if(

color

==

random(

MaxColors

)

)

/*

Used

to

keep

RANDOM

in

sync

*/

putpixel(

x,

y,

0

)

/*

Write

pixel

to

BLACK

*/

}

Pause()

/*

Wait

for

user's

response

*/

}

看这几个输出,是错的。第一组不用说了吧;第二三组当只有1个时,输出应当是1

0

0,而不是1;第四组也不说了。

我觉得你的代码不是挺对的,而是很糟糕,思想太简单。acm题偶尔有那么几道水题,但大部分还是难题,很残酷的。