2013年4月13日 星期六

物件導向期中考-所有小考程式詳解

ex0226a
class ex0226a{
	public static void main(String[] args)
	{
		String fName="John", lName="Chen";
		int weight=56;               // weight: Kg
		int height=175;              // height: cm
		int age=20;
		boolean gender=true;

		// 1cm = 0.0328 英呎
		// 1kg  = 2.21 磅

		System.out.println(" Name: "+fName+" "+ lName);
		System.out.println(" Gender: "+gen(gender));
		System.out.println(" weight: "+wei(weight)+" 磅 ");
		System.out.println(" height: "+hei(height)+" 英呎 ");
	}
	public static String gen(boolean gen)
	{
        if(gen=true) return "Man";
        else return "Female";
	}
	public static Double wei(int wei)
	{
        return wei*2.21;
	}
	public static Double hei(int hei)
	{
        return hei*0.0328;
	}



}

ex0305a
import java.io.*;

class ex0305a{
	public static void main(String[] args) throws IOException{
//
//              input a string & transfer into a integer
//   
                System.out.print(" Input a number :");
	BufferedReader br =new 
		BufferedReader(new InputStreamReader(System.in));
	String str=br.readLine();
	int fee=Integer.parseInt(str);
//
                System.out.println(" NT1000 :" +fee/1000 );
		fee%=1000;
                System.out.println(" NT500 :" + fee/500);
		fee%=500;
                System.out.println(" NT100 :" + fee/100);
		fee%=100;
                System.out.println(" NT50 :" + fee/50);
		fee%=50;
                System.out.println(" NT10 :" + fee/10);
		fee%=10;
                System.out.println(" NT5 :" + fee/5);
		fee%=5;
                System.out.println(" NT1 :" + fee/1);

	}
}
ex0312a
class ex0312a{
        public static void main(String[] args){
	int data[]={81,95,66,80,77,51,69,33,-1,46,90,87,93,72,63,55,-1,65,66,71,50,88,47,49,83,61};

//       
//     Statistic A, B, C, D, Fail & absent students number
//
//    Accumulate total score and total number (except absent students)
//
	int na=0,nb=0,nc=0,nd=0,fn=0,an=0,sum=0;
	for(int i:data){
		if(i>=0){
			sum+=i;
			if(i>=90) na++;
			else if(i>=80) nb++;
			else if(i>=70) nc++;
			else if(i>=60) nd++;
			else fn++;

		}
		else
		an++;
	}

		System.out.println(" Number of A :"+na);
		System.out.println(" Number of B :"+nb);
		System.out.println(" Number of C :"+nc);
		System.out.println(" Number of D :"+nd);
		System.out.println(" Fail Number :"+fn);
		System.out.println(" Absent Number  :"+ an);
		System.out.println(" *** Average :"+avg(sum,data.length-an));
        }
//
// sum: total score (except absent students)
//
// num: total number (except absent students)
//
	public static double avg(int sum, int num){
		double tmp;
		int tmp1;

		tmp=(double)sum/num;
		tmp1=(int)(tmp*10);
		return tmp1/10.0;
	}
}

ex0319b
class ex0319b{
	public static void main(String[] args) 
	{
		int[][] matA={{1,2,3},{4,5,6},{7,8,9}};
		int[][] matB={{1,7,6,4,3},{2,1,5,7,9},{4,3,5,1,7}};
		int[][] matC=new int[3][5];
		// Declate and allocate two dimension int array ==> matC
		int sum=0;

                                  mtrPtr(matA);
		System.out.println("=====================================");
                                  mtrPtr(matB);
                for(int i=0;i<matC.length;i++){
			for(int j=0;j<matC[i].length;j++){
				sum=0;
				for(int k=0;k<matC.length;k++)
					sum=sum+matA[i][k]*matB[k][j];
				matC[i][j]=sum;
			}
		}
		System.out.println("=====================================");
                                  mtrPtr(matC);
	}
	public static void mtrPtr(int[][] mat){
        for(int i=0;i<mat.length;i++){
			for(int j=0;j<mat[i].length;j++)
				System.out.print("  "+mat[i][j]+"\t");
			System.out.println();
		}
	}
}

ex0326b
class student{
	String name;
	int age;
	boolean gender;

	student(){};
	void setName(String nn){
		name=nn;
	}
	String getName(){
		return name;
	}

	void setAge(int nn){
		age=nn;
	}
	int getAge(){
		return age;
	}

	void setGender(boolean nn){
		gender=nn;
	}
	boolean getGender(){
		return gender;
	}
}

class ex0326b{
	public static void main(String[] args) 
	{
		student std01=new student();
		std01.setName("Mary Chen");
		std01.setAge(20);
		std01.setGender(true);
		System.out.println(" Std name: "+std01.getName());
		System.out.println(" Std age: "+std01.getAge());
		System.out.println(" Std gender: "+std01.getGender());
	}
}

ex0326d
class score{
	int[] data;
	int base=60;

	score(int[] dd){ data=dd;}
	int getHigh(){
        	int high=0;
		for(int i:data) if(i>high) high=i;
		return high;
	}
	int passNo(){
		int count=0;
		for(int i:data) if(i>=base) count++;
		return count;
	}
	float getAvg(){
		float sum=0f;
		for(int i:data) sum+=i;
		return sum/(float) data.length;
	}
}

class ex0326d{
	public static void main(String[] args) 
	{
		int[] dataA={99,88,77,66,55,44,92,56};
		int[] dataB={63,57,89,73,61,72,78,47,76,85,63,90,51,68,39};
		int[] dataC={79,78,47,96,85,54,80,66,73,52,84,73,97,60,55,70,65};
		score itmA=new score(dataA);
		score itmB=new score(dataB);
		score itmC=new score(dataC);

		System.out.println(" Highest score of itmA: "+itmA.getHigh());
		System.out.println(" Pass No of itmA: "+itmA.passNo());
		System.out.println(" Average of itmA: "+itmA.getAvg());
		System.out.println(" Highest score of itmB: "+itmB.getHigh());
		System.out.println(" Pass No of itmB: "+itmB.passNo());
		System.out.println(" Average of itmB: "+itmB.getAvg());
		System.out.println(" Highest score of itmC: "+itmC.getHigh());
		System.out.println(" Pass No of itmC: "+itmC.passNo());
		System.out.println(" Average of itmC: "+itmC.getAvg());
		System.out.println(" *Highest score of all: "+getMax(itmA.getHigh(),itmB.getHigh(),itmC.getHigh()));
		System.out.println(" *Pass No of all: "+(itmA.passNo()+itmB.passNo()+itmC.passNo()));
		System.out.println(" *Average of all: "+(itmA.getAvg()+itmB.getAvg()+itmC.getAvg())/3);
	}
	public static int getMax(int a, int b, int c){
		if(a > b)
			if( a > c) return a;
			else return c;
		else
			if(b > c) return b;
			else return c;
	}
}

ex0326x
class ex0326x{
	public static void main(String[] args) 
	{
		int[][] fee={{45,40,50,30,45},{100,95,80,90,110},
                                                     {90,85,120,110,150}};
		int[] sumDay=new int[5];
		int[] sumBld=new int[3];
		int sum=0;

		for(int i=0;i<3;i++){
			sum=0;
			for(int j=0;j<5;j++){
				sum=sum+fee[i][j];
			}
			sumBld[i]=sum;
		}
		for(int j=0;j<5;j++){
			sum=0;
			for(int i=0;i<3;i++){
				sum=sum+fee[i][j];
			}
			sumDay[j]=sum;
		}	
                                  mtrPtr(fee);
		System.out.println("  Total fee of Breakfast, Lunch and dinner: "+
                                                             sumBld[0]+"  "+sumBld[1]+"  "+sumBld[2]);
		System.out.print("  Total fee of each day: ");
		for(int df: sumDay) System.out.print("  "+df);
		System.out.println();
	}
	public static void mtrPtr(int[][] mat){
                                  for(int i=0;i<mat.length;i++){
			for(int j=0;j<mat[0].length;j++)
				System.out.print("  "+mat[i][j]+"\t");
			System.out.println();
		}
	}
}

ex0409b
class point{
	int x, y;

	point(){ 
		x=0;
		y=0;
	}
	
	point(int x, int y){
		this.x=x;
		this.y=y;
	}

	double distance(){   // Distance from point to origin 
		return (int) (Math.sqrt(x*x+y*y)*100)/100.0;	
	}
	int location(){
		if(x==0 && y==0) return 0;       // on origin
		if(x>0 && y>0) return 1;           // on 1st quadrant
		if(x<0 && y>0)  return 2;          // on 2nd quadrant
		if(x<0 && y<0)  return 3;          // on 3rd quadrant
		if(x>0 && y<0) return 4;           // on 4thquadrant
		if(y==0) return 5;                     // on X axle
		return 6;                                  // on Y axle
	}
	int disX(){     // Distance from point to X axle 
		return Math.abs(y);	
	}
	int disY(){    // Distance from point to Y axle
		return Math.abs(x);	
	}
}

class ex0409b{
	public static void main(String[] args) 
	{
		// create 3 points object;
                               // point1 ==> (0, 0), point2 ==> (4, 7), point3 ==> (-5 ,3)

		point p1 = new point();
		point p2 = new point(4,7);
		point p3 = new point(-5,3);

		System.out.println(" Location of point1: "+p1.location());
		System.out.println(" Location of ponit2: "+p2.location() );
		System.out.println(" Location of point3: "+p3.location() );

		System.out.println(" Distance of point1: "+p1.distance() );
		System.out.println(" Distance of point2: "+p2.distance() );
		System.out.println(" Distance of point3: "+p3.distance() );

		System.out.println(" Distance point2 to X : "+p2.disX() );
		System.out.println(" Distance point2 to Y : "+p2.disY() );
		System.out.println(" Distance point3 to X : "+p3.disX() );
		System.out.println(" Distance point3 to Y : "+p3.disY() );
	}
}

test1
class test1{
	public static void main(String[] args) 
	{
		int aa=-1,bb,cc,dd;

		bb=aa>>1;
		cc=aa>>>1;
		dd=aa<<1;
		System.out.println("   aa >> 1 "+ bb);
		System.out.println("   aa >>> 1 "+ cc);
		System.out.println("   aa << 1 "+ dd);
	}
}

2013年3月1日 星期五

Ma apologizes for 228



President Ma Ying-jeou apologized on behalf of the nation for the 228
Massacre yesterday, on the 66th anniversary of the tragic event.

Ma pledged at the ceremony that his administration will uphold rule of law,
protect human rights and promote cross-strait peace to prevent such a tragedy
from ever happening again.

Historians estimate that between 10-thousand and 30-thousand Taiwanese people
- many of them intellectuals - were killed by the Kuomintang in the brutal
crackdown on anti-government uprisings that began on February 28th, 1947,
shortly after the end of Japanese colonial rule.

The incident marked the beginning of the Kuomintang's White Terror period in
Taiwan, in which thousands more inhabitants vanished, died, or were
imprisoned.

馬道歉228
馬英九總統道歉,代表國家的228
大屠殺昨天,第66週年悲慘事件。

馬在儀式上承諾,他的政府堅持法治,
保護人權和促進兩岸和平,防止這樣的悲劇
再次發生。

歷史學家估計,在10萬和30萬台灣人
- 他們許多的知識分子 - 國民黨在殘酷的殺害
鎮壓反政府起義,於1947年2月28日開始,
日本殖民統治結束後不久。

該事件標誌著國民黨的白色恐怖時期
台灣,數千居民消失了,死了,或
監禁

2013年1月1日 星期二

多媒體製作

動腦遊戲3
import flash.events.MouseEvent;
import flash.ui.Mouse;


stop();
result_txt.visible=false;
/*
answerA_mc.addEventListener(MouseEvent.CLICK ,pressA);
function pressA(event:MouseEvent) {
 answerA_mc.visible=false;
 answerB_mc.visible=false;
 answerC_mc.visible=false;
 //trace("A");
}
*/

answerA_mc.addEventListener(MouseEvent.CLICK, pressA);
function pressA(me:MouseEvent){
 result_txt.visible=true;
 result_txt.text="答對!";
}

answerB_mc.addEventListener(MouseEvent.CLICK, pressB);
function pressB(me:MouseEvent){
 result_txt.text="答錯!";
 result_txt.visible=true;
}
answerC_mc.addEventListener(MouseEvent.CLICK, pressC);
function pressC(me:MouseEvent){
 result_txt.text="答錯!";
 result_txt.visible=true;
}
遙控直升機遊戲
/*right_btn.addEventListener(MouseEvent.MOUSE_OVER, plane_right);
function plane_right(me:MouseEvent){
 plane_mc.x += 5 ;
}

left_btn.addEventListener(MouseEvent.CLICK, plane_left);
function plane_left(me:MouseEvent){
 plane_mc.x -= 5 ;
}
up_btn.addEventListener(MouseEvent.CLICK, plane_up);
function plane_up(me:MouseEvent){
 plane_mc.y -= 5 ;
}

down_btn.addEventListener(MouseEvent.CLICK, plane_down);
function plane_down(me:MouseEvent){
 plane_mc.y += 5 ;
}
*/

//定義四個方向速度
var left:Number=0;
var right:Number=0;
var up:Number=0;
var down:Number=0;

//定義速度speed
var speed:Number=10;


up_btn.addEventListener(MouseEvent.MOUSE_OVER, upOver);
function upOver(me:MouseEvent){
 up = -speed;
}
up_btn.addEventListener(MouseEvent.MOUSE_OUT, upOUT);
function upOUT(me:MouseEvent){
 up = 0;
}
down_btn.addEventListener(MouseEvent.MOUSE_OVER, downOver);
function downOver(me:MouseEvent){
 down = speed;
}
down_btn.addEventListener(MouseEvent.MOUSE_OUT, downOUT);
function downOUT(me:MouseEvent){
 down = 0;
}
left_btn.addEventListener(MouseEvent.MOUSE_OVER, leftOver);
function leftOver(me:MouseEvent){
 left = -speed;
 plane_mc.rotation = -10;
}
left_btn.addEventListener(MouseEvent.MOUSE_OUT, leftOUT);
function leftOUT(me:MouseEvent){
 left = 0;
 plane_mc.rotation = 0;
}
right_btn.addEventListener(MouseEvent.MOUSE_OVER, rightOver);
function rightOver(me:MouseEvent){
 right = speed;
 plane_mc.rotation = 10;
}
right_btn.addEventListener(MouseEvent.MOUSE_OUT, rightOUT);
function rightOUT(me:MouseEvent){
 right = 0;
 plane_mc.rotation = 0;
}

//不停更新飛機的四個方向速度
this.addEventListener(Event.ENTER_FRAME, EnterFrame);
function EnterFrame(me:Event){
 plane_mc.x += right;
 plane_mc.x += left;
 plane_mc.y += up;
 plane_mc.y += down;
 
 //邊界處理
if (plane_mc.x > stage.stageWidth){
 plane_mc.x = 0;
}
if (plane_mc.x < 0){
 plane_mc.x = stage.stageWidth;
}

if (plane_mc.y > stage.stageHeight){
 plane_mc.y = 0;
}
if (plane_mc.y < 0){
 plane_mc.y = stage.stageHeight;
}
 
}

3.3水果選單
chk_btn.addEventListener(MouseEvent.CLICK, chk);
function chk(me:MouseEvent){
 //trace(input_txt.text);
 switch (input_txt.text.toLowerCase()) {
  case "a":
    result_txt.text = "您選Apple";
    break;
  case "b":
    result_txt.text = "您選Banana";
    break;
  case "c":
    result_txt.text = "您選Coconut";
    break;
  default:
    result_txt.text = "您選的不在選單內";
 }
}
3.3判斷奇偶數
check_btn.addEventListener(MouseEvent.CLICK , chk);
function chk(me:MouseEvent){
 if (int(input_txt.text) % 2 == 0) {
  result_txt.text = "偶數";
 }else{
  result_txt.text = "奇數";  
 }
}
4.1播放停止
this.stop();

// For Scene
play_btn.addEventListener(MouseEvent.CLICK, man_move);
function man_move(me:MouseEvent){
 this.play();
}

stop_btn.addEventListener(MouseEvent.CLICK, man_stop);
function man_stop(me:MouseEvent){
 this.stop();
}

// For man_mc
play2_btn.addEventListener(MouseEvent.CLICK, man_move2);
function man_move2(me:MouseEvent){
 man_mc.play();
}

stop2_btn.addEventListener(MouseEvent.CLICK, man_stop2);
function man_stop2(me:MouseEvent){
 man_mc.stop();
}
4.3地球停止
globe_mc.stop();

globe_mc.addEventListener(MouseEvent.MOUSE_OVER, mouse_in);

function mouse_in(me:MouseEvent){
 globe_mc.play();
}

globe_mc.addEventListener(MouseEvent.MOUSE_OUT, mouse_out);

function mouse_out(me:MouseEvent){
 globe_mc.stop();
}
4.3利用按鈕切換
stop();

right_btn.addEventListener(MouseEvent.CLICK, nextF);
function nextF(me:MouseEvent){
 if(this.currentFrame >= 5){
  this.gotoAndStop(1);
 }else{
  this.nextFrame();
 }
}

left_btn.addEventListener(MouseEvent.CLICK, prevF);
function prevF(me:MouseEvent){
 if(this.currentFrame <= 1){
  this.gotoAndStop(5);
 }else{
  this.prevFrame();
 }
}
4.3影格切換
stop();
a_mc.stop();

next_btn.addEventListener(MouseEvent.CLICK, nextF);
function nextF(me:MouseEvent){
 if (a_mc.currentFrame < 5){
  a_mc.nextFrame();
 } else{
  a_mc.gotoAndStop(1);
 }
}

prev_btn.addEventListener(MouseEvent.CLICK, prevF);
function prevF(me:MouseEvent){
 if(a_mc.currentFrame > 1){
  a_mc.prevFrame();
 }else{
  a_mc.gotoAndStop(5);
 }
}

4.4跳場景停止
this.stop();

a_btn.addEventListener(MouseEvent.CLICK, wrong);
function wrong(me:MouseEvent){
 this.gotoAndStop(2);
}

b_btn.addEventListener(MouseEvent.CLICK, right);
function right(me:MouseEvent){
 this.gotoAndStop(3);
}
4.5切換5照片
//Scene 1
stop();

next_btn.addEventListener(MouseEvent.CLICK, next_scene);

function next_scene(me:MouseEvent){
 nextScene();
}

function back_scene(me:MouseEvent){
 prevScene();
}

//Scene 2-4
stop();

next_btn.addEventListener(MouseEvent.CLICK, next_scene);
back_btn.addEventListener(MouseEvent.CLICK, back_scene);

//Scene 5
stop();

back_btn.addEventListener(MouseEvent.CLICK, back_scene);
4.5選擇播放
stop(); //影格15及35也須停止

a_btn.addEventListener(MouseEvent.CLICK, playA);
function playA(me:MouseEvent){
 this.gotoAndPlay("聖誕老人");
}

b_btn.addEventListener(MouseEvent.CLICK, playB);
function playB(me:MouseEvent){
 this.gotoAndPlay("聖誕樹");
}
4.7延遲播放
stop();

var timer=setTimeout(startPlay, 3000);
function startPlay(){
 play();
 clearTimeout(timer);  
}
4.8控制影片播放速度
wheel_mc.stop();

var actMode;
var Rot=0;
var playStep=0;
var Pn=1;

drag_btn.addEventListener(MouseEvent.MOUSE_DOWN, chgYes);
function chgYes(me:MouseEvent){
 actMode = "yes";
}


drag_btn.addEventListener(MouseEvent.MOUSE_UP, chgNo);
function chgNo(me:MouseEvent){
 actMode = "no";
}

jog_mc.addEventListener(MouseEvent.MOUSE_OVER, chkRot);
function chkRot(me:MouseEvent){
 if(actMode == "yes"){
  Rot = Math.atan2(jog_mc.mouseX, -jog_mc.mouseY) * 180 / Math.PI;
  drag_btn.rotation = Rot;
 }
}

this.addEventListener(Event.ENTER_FRAME, cirPlay);
function cirPlay(me:Event){
 playStep = Math.floor(Math.abs(Rot)/30);
 if (playStep>5){
  playStep = 5;
 }
 
 Pn = 1;
 if (Rot < 0){
  Pn = -1;
 }
 
 for (var i=1; i<= playStep; i++) {
  if (Pn > 0) {
   wheel_mc.nextFrame();
   if (wheel_mc.currentFrame == wheel_mc.totalFrames){
    wheel_mc.gotoAndPlay(1);
   }
  }else{
   wheel_mc.prevFrame();
   if (wheel_mc.currentFrame == 1){
    wheel_mc.gotoAndPlay(wheel_mc.totalFrames);
   }
  }
 } 

 fps_txt.text = String(playStep * 12 * Pn);

}



4.9動態控制SWF
fullscreen_btn.addEventListener(MouseEvent.CLICK, fullscreen);
function fullscreen(me:MouseEvent){
 fscommand("fullscreen","true");
}

quit_btn.addEventListener(MouseEvent.CLICK, quit);
function quit(me:MouseEvent){
 fscommand("quit");
}

menu_btn.addEventListener(MouseEvent.CLICK, menu);
function menu(me:MouseEvent){
 //stage.showDefaultContextMenu = false;
 stage.showDefaultContextMenu = !stage.showDefaultContextMenu;
}

5.1動態加入
stage.addEventListener(MouseEvent.CLICK, copyMC);

function copyMC(me:MouseEvent) {
 var tigerCopy_mc:tiger = new tiger();
 stage.addChild(tigerCopy_mc);
 tigerCopy_mc.x=this.mouseX;
 tigerCopy_mc.y=this.mouseY;

}
5.2動態移除
var addNum:int = 10; //斑馬數量
var basicIndex: Number = this.numChildren -1;

sh_mc.startDrag(true);

//建立舞台上斑馬
for(var i:int=0; i < addNum; i++){
 var horseCopy:horse = new horse();
 horseCopy.x = 500 * Math.random();
 horseCopy.y = 350 * Math.random(); 
 horseCopy.scaleX = horseCopy.scaleY = Math.floor(Math.random() * 10) / 10; 
 this.addChild(horseCopy);
}

//依滑鼠點選移除斑馬
stage.addEventListener(MouseEvent.CLICK, delMc);
function delMc(me:MouseEvent){
 if( basicIndex < this.getChildIndex(me.target)){
  this.removeChild(me.target);
 }
}
5.3反彈球
var speed:Number = 10;
var speed_x:Number = speed;
var speed_y:Number = speed;

stage.addEventListener(Event.ENTER_FRAME, gogo);
function gogo(me:Event){
 with (ball_mc){
  x += speed_x;
  y += speed_y;
  
  if (x>stage.stageWidth){
   x = stage.stageWidth;
   speed_x = -speed;
  }else if ( x < 0){
   x= 0;
   speed_x = speed;
  }

  if (y>stage.stageHeight){
   y = stage.stageHeight;
   speed_y = -speed;
  }else if ( y < 0){
   y= 0;
   speed_y = speed;
  }

  
 }
}


5.5顏色轉換
var color_arr:Array = [0xFF0000, 0xFFFF00, 0x00FFFF, 0x0000FF];

var listNum:int = color_arr.length;

var trans:Transform = new Transform(color_mc);
var my_color:ColorTransform = new ColorTransform();

setInterval(chgcolor, 2000);

function chgcolor(){
 var num:int = Math.floor(Math.random() * listNum);
 my_color.color = color_arr[num];
 trans.colorTransform = my_color;
 
}

5.6衣服變色
var color_array=[0xFF0000,0x00FF00,0x0000FF,0x00FFFF,0xFFFF00,0xFF00FF,0x9900FF,0xCCCCFF,0xFF9900,0xCC9900,0x3399CC];

a_btn.addEventListener(MouseEvent.CLICK, chgcolor);
b_btn.addEventListener(MouseEvent.CLICK, chgcolor);
c_btn.addEventListener(MouseEvent.CLICK, chgcolor);
d_btn.addEventListener(MouseEvent.CLICK, chgcolor);
e_btn.addEventListener(MouseEvent.CLICK, chgcolor);
f_btn.addEventListener(MouseEvent.CLICK, chgcolor);
g_btn.addEventListener(MouseEvent.CLICK, chgcolor);
h_btn.addEventListener(MouseEvent.CLICK, chgcolor);
i_btn.addEventListener(MouseEvent.CLICK, chgcolor);
j_btn.addEventListener(MouseEvent.CLICK, chgcolor);
k_btn.addEventListener(MouseEvent.CLICK, chgcolor);


function chgcolor(me:MouseEvent){
 var my_color:ColorTransform = new ColorTransform();
 
 switch (me.target.name) {
  case "a_btn":
   my_color.color = color_array[0];
   break;
  case "b_btn":
   my_color.color = color_array[1];
   break;
  case "c_btn":
   my_color.color = color_array[2];
   break;
  case "d_btn":
   my_color.color = color_array[3];
   break;
  case "e_btn":
   my_color.color = color_array[4];
   break;
  case "f_btn":
   my_color.color = color_array[5];
   break;
  case "g_btn":
   my_color.color = color_array[6];
   break;
  case "h_btn":
   my_color.color = color_array[7];
   break;
  case "i_btn":
   my_color.color = color_array[8];
   break;
  case "j_btn":
   my_color.color = color_array[9];
   break;
  case "k_btn":
   my_color.color = color_array[10];
   break;
 }
  
 cloth_mc.transform.colorTransform = my_color;
 
}


5.7 廣告位移
stop();
var speed:Number = 0;

stage.addEventListener(Event.ENTER_FRAME, go);
function go(me:Event){
 speed = (stage.stageWidth/2 - this.mouseX) / 10; 
 movie_mc.x += speed;
 
 if(movie_mc.x < 0 || movie_mc.x > 850){
  movie_mc.x = 850;
 }
 
}
5.8顫慄的男孩
var strong:Number = 10;

var initX:Number = realboy_mc.x;
var initY:Number = realboy_mc.y;

shakeboy_mc.x = initX;
shakeboy_mc.y = initY;

stage.addEventListener (Event.ENTER_FRAME, goshake);

function goshake(me:Event){
 shakeboy_mc.x = initX + shake(); 
 shakeboy_mc.y = initY + shake(); 
}

function shake(){
 return (Math.floor(Math.random()*strong) - strong/2 ); 
}
5.9 雪花飄
// 場景1的影格1
var snowNum:Number = 30;

for (var i:int=0; i<snowNum; i++){
 var mysnow:snow = new snow();
 this.addChild(mysnow);
}

// 雪花元件的影格1
this.x = Math.random() * stage.stageWidth;
this.y = Math.random() * stage.stageHeight;

// 雪花元件的影格2
this.y += Math.random() * 5 + 1; 
this.x += Math.random() * 5 - 2.5; 

// 雪花元件的影格3
if (this.y> stage.stageHeight){
 //this.y = 0;
 gotoAndPlay(1);
} else{
 gotoAndPlay(2);
}

5.10 遮罩開場
basic_mc.visible = false;
mask_mc.visible = false;
mask_mc.stop();

stage.addEventListener(MouseEvent.CLICK, smask);

function smask(me:MouseEvent){
 start_txt.visible =false;
 basic_mc.visible = true;
 mask_mc.visible = true;
 basic_mc.mask = mask_mc;
 mask_mc.play();
}

2013編譯娘

21
#include<stdio.h>
#include "stoprun.c"
int dx(int x, int a[], int n){
int sum=0,i,j,r=1;
for(i=n-2,j=1;i>=0;i--,j++){
sum+=a[i]*j*r;
r*=x;
}
return sum;
}
main(int argc, char *argv[]){
 stoprun();
 int x, n;
 for(;;){
  if(scanf("%d%d", &x, &n)<0) break;
  int a[n],i;
for(i=0;i<n;i++) scanf("%d",&a[i]);
  printf("%d\n", dx(x,a,n));
 }
}
22
#include<stdio.h>
#include "stoprun.c"
main(int argc, char *argv[]){
 stoprun();
int n,i,sum=0,score;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&score);
sum+=score;
}
printf("Total score is %d\n",sum);
printf("Float average is %f\n",sum*1.0/n);
printf("Integer average is %d\n",sum/n);
sum=(sum*1.0/n*10+5)/10;
printf("Rounded Integer average is %d\n",sum);
}
23
#include<stdio.h>
#include "stoprun.c"
int getprime(int,int[]);
main(int argc, char *argv[]){
 stoprun();
 int n;
 int prime[200],x;
 scanf("%d", &n);
 int no=getprime(n,prime);
 for(x=0;x<no;++x) {
  printf("prime[%d]=%d\n",x,prime[x]);
 }
}
int getprime(int num, int p[]) {
int i,j,m,nc=0;
for(i=2;i<=num;i++){
for(j=2,m=1;j<i;j++)
if(i%j==0) m=0;
if(m) p[nc++]=i;
}
return nc;
}
24
#include<stdio.h>
#include "stoprun.c"
void int2decimal(int,char[]);
main(int argc, char *argv[]){
 stoprun();
 int number;
 char decimal[32];
 for(;;) {
  if(scanf("%d", &number)<0) break;
  int2decimal(number,decimal);
  printf("Decimal(%d)=\"%s\"\n",number,decimal);
 }
}
void int2decimal(int n,char d[]){
int i=0,j;
if(n==0) d[i++]='0';
while(n){
if(i%4==3)d[i++]=',';
d[i]=n%10+'0',n/=10;
i++;
}
d[i]='\0';

for(--i,j=0;j<i;j++,i--){
int t;
t=d[i],d[i]=d[j],d[j]=t;
}
}
25
#include<stdio.h>
#include "stoprun.c"
void calendar(int fday,int days)
{
printf("| S  M  T  W  T  F  S|\n");
printf("|--------------------|\n|");
int i;
for(i=0;i<fday+days;i++){
if(i%7==0&&i!=0) printf("|\n|");
else if(i!=0) printf(" ");
if(i<fday) printf("  ");
else printf("%2d",i-fday+1);
}
while(i%7!=0) printf("   "),i++;
printf("|\n|--------------------|\n");
}
main(int argc, char *argv[]){
 stoprun();
 int year, month, week;
 scanf("%d%d%d", &year, &month, &week);
int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(year%4==0&&year%100!=0||year%400==0) m[1]=29;
int days=m[month-1];
year-=1911;
 printf("|*******%03d-%02d*******|\n", year, month);
 calendar(week, days);
}

2012年12月26日 星期三

研究所
台大:
1.英文(A):成績不計入考試總分計算,惟成績未達該科本校到考生前80%者,不予錄取。
2.數學(含線性代數、離散數學) 
3.計算機系統(含計算機結構、作業系統)
4.軟體設計(含資料結構、演算法)
台大資工:
         線代:投資報酬率低,簡單的很簡單 難的很難,
              算子(黃子嘉第八章)和求反矩陣的方法要熟一點
         離散:要廣,幾乎都不能放棄,代數簡單的要會,
              圖論證明要記,其他的證明能記就記

         計組:往年滿正常的,今年很奇怪,建議之後算盤本第0張要看一下...
              台大教授上課投影片能拿則拿 考題能拿則拿

         OS  :分散式系統考很多...(要特別準備台大OS,這個最好不要放棄)
              台大教授上課投影片能拿則拿 考題能拿則拿
               (聽說今年OS是非題,滿多上課投影片有)

        ALGO & DS: 97年考一堆ALGO,今年考滿多DS,建議明年是不要賭,
                   有時間的話,ALGO重要的地方都要會


2012年12月24日 星期一

ITSA20

 
#include<stdio.h>
int main(){
    int n,i,j,cas=1;
    while(scanf("%d",&n)!=EOF){
        long long s[20],max=0,tmp;
        for(i=0;i<n;i++) scanf("%lld",&s[i]);
        for(i=0;i<n;i++){
            tmp=1;
            //max=(max<tmp)? tmp:max;
            for(j=i;j<n;j++){
                tmp*=s[j];
                max=(max<tmp)? tmp:max;
            }
        }
        printf( "Case #%d: The maximum product is %lld.\n\n", cas++, max );
    }
return 0;
}

ITSA19

 
#include<stdio.h>
int main(){
    long long x,fun[200000];
    char str[200000];
    while(~scanf("%lld",&x)){
        int top=0,num=0,i,j,op=1;
        getchar();
        gets(str);
        for(i=0;str[i];i++){
            if(str[i]!=' '){
            if(str[i]=='-') op=-1,i++;
                num*=10;
                num+=str[i]-'0';
            }
            else{
                fun[top++]=num*op;

                num=0;
                op=1;
            }
        }
        fun[top++]=num*op;
        long long sum=0,r=1;
        for(i=top-2,j=1;i>=0;j++,i--){
            sum+=j*fun[i]*r;
            r*=x;
        }
        printf("%lld\n",sum);
    }
return 0;
}