2018年4月29日 星期日

c++ 直角三角形 米字

#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the isosceles triangle's cathetus:  ";  
int ca;
cin >> ca;
//isosceles triangle
for(int i=1;i<=ca;i++)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
system("pause");
return 0;
}






#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the length: ";
int ca;
cin >> ca;
//the triangle
for(int i=ca;i>0;i--)//control the amount of *
{
for(int j=1;j<=i;j++)//control the row
{
cout<<"*";
}
cout<<endl;
}
system("pause");
return 0;
}


#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "input the length: ";
int ca;
cin >> ca;
//triangle
for(int i=1;i<=ca;i++)//控制星星數 
{
for(int j=1;j<=ca;j++)//控制行數 
{
if( j<=(ca-i) )
{
cout << " ";
}
else
{
cout << "*";
}
}
cout <<endl;
}

}

















#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the length: ";
int ca;
cin >> ca;
//triangle
for(int i=1;i<=ca;i++)
{
for(int j=1;j<=ca;j++)//控制行數 
{
if(j>=i)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout <<endl;

system("pause");
return 0;




2018年4月27日 星期五

//c++ 字母排序

#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
char s[10], t[10];int k[10], temp;
cout << "輸入十個英文字母(大小皆可): " <<endl;
//[input]
for(int i=0;i<10;i++){
cin >> s[i];
//cout << s[i];
k[i] = s[i];//字元→ASCII
//cout <<k[i]<<endl;
}
//[sort]
//選擇排序法
for(int i=0;i<10;i++)
{
for(int j=i+1; j<10; j++)
{
if(k[i]>k[j])
{
temp=k[i];
k[i]=k[j];
k[j]=temp;
}
}
}
//[output]
for(int i=0;i<10;i++)
{
t[i]=k[i];//ASCII→字元
cout << t[i];
}
system("pause");
return 0;
 }



//c++ 通話費計算

。題目:
有一家電信公司的計費方式:
每個月打800分鐘以下(不含800),每分鐘0.5元;
打800-1500分鐘時,所有電話費以95折計算;
打1500分鐘以上(不含1500),則通話費以8折計算。
請寫出一個程式,可由使用者輸入通話分鐘,程式即輸出其費用。


#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int t=0;
cout<<"請輸入通話時間(分鐘):";
cin>>t;
if(t<800)
{
if(t%2==0)
t*=0.5;
else
t=t*0.5+1;
cout<<"\n您的電話費是: "<<t<<"元\n";
}
else if(t<=1500)
{
t=t*95*5;
if(t%1000>0)
t=t/1000+1;
else
t/=1000;
cout<<"\n您的電話費是: "<<t<<"元\n"; 
}
else if(t>1500)
{
t=t*4;
if(t%10>0)
t=t/10+1;
else
t/=10;
cout<<"\n您的電話費是: "<<t<<"元\n";
}
}

2018年4月20日 星期五



「鈴!鈴!」
微風輕搖窗邊的晴天娃娃造型的風鈴,小二那年我父親送我的生日禮物。


在這溫度恰到好處的春日早晨,我坐於書桌前,緩緩地翻著小時的札記,從前的歡樂浮出了紙張,不斷地,不斷地,席捲著我的心頭。透過窗戶灑進來的晨陽,在玻璃的折與反,映射出了絢爛的霓虹世界,成了我回憶裡的夢幻。隨著風輕拂的花兒,華麗地揮灑著身上的露珠,與青草地彈奏曲曲柔和的旋律,繞於身旁。


彷彿,獨自乘著一艘小帆。徜徉於汪洋,隨著波浪的起舞享受自然的韻律。遠方,是天與海相互交織成的藝術,天的淡藍寬闊、海的深藍厚實,照映了彼此。海鷗們哼著宏亮的音譜,我想,亦是在讚嘆著眼前的美好吧!


美好,卻在這時離開,帶走了一片雲彩。天色逐漸暗沉,就連最後一絲光芒也毫不慰留,被烏雲給遮住了雙眼,漆黑一片。「隆!」「隆!」天空嘶吼著,好像要將天撕裂了一般,閃電也狠心地劃破天際。「不!不!」我雙手緊摀著耳朵,奮力地將眼皮闔起,整個人蜷曲一旁,窩在小帆的角落。心理,祈禱著,不斷地祈禱著這一切能馬上結束,希望甚麼都沒發生過。但是,錯了,無情的巨浪將我吞噬,連同小帆,成了他的美味佳餚,漸漸失去。


「鈴!鈴!」

原來是我睡著了,還好只是個夢啊!鈴聲再次搖響了我,將我拉出黑洞般的世界,要我記得眼前的現在,是溫暖。謝謝你,鈴。

20180420
00:32筆

2018年4月14日 星期六

// C++ 九九乘法表

//九九乘法表 
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
cout<<j<<"*"<<i<<'='<< setw(2) <<i*j<<' ';
}
cout<<endl;
}
return 0;
}








//法二
//以while迴圈

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int i=1,j=1;
while(i<10)
{
while(j<10)
{
cout<<i<<"x"<<j<<"="<<i*j;
cout<<"\t"<<i+1<<"x"<<j<<"="<<(i+1)*j;
cout<<"\t"<<i+2<<"x"<<j<<"="<<(i+2)*j;
j+=1;
cout<<endl;
}
j=1;
i+=3;
cout<<endl;
}
system("pause");
return 0;
}

//C++ 找出某範圍的所有質數

//找出到n範圍的所有質數 
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{ //使用者輸入 
int n;
cout << "Please input a number:" ;
cin >> n;

for(int i=2; i<=n; i++)
{
bool factor=false;
//找出質數 
for(int j=2; j<i; j++)
{
if(i%j==0)
factor=true;
}
//若為質數在印出 
if(factor==false)
{
cout << i <<endl;
}
}
system("pause");
return 0;
}









// C++ 質數判別

//質數判別 
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
int n;
cout << "Please input a number:" ;
cin >> n;
bool factor=false;
for(int i=2; i<n; i++)
{
if( n%i==0 ) factor=true;
}

if(factor)
cout << endl << "NO" ;
else 
cout << endl << "YES" ;

system("pause");
return 0;
}

2018年3月8日 星期四

Stopping by Woods on a Snowy Evening 英文/中文

Stopping by Woods on a Snowy Evening

Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.
My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.

//====translation====

雪晚林邊歇馬

我想我認得這座森林
林主的屋子就在前面小村莊
他卻看不見我於此停歇
凝望白茫茫的雪景

我想牠現在一定深感疑惑
在這不見農莊之處停留
在寒林與冰湖間停下
於最黝黑的黃昏下

牠輕輕搖響韁鈴
似乎在詢問是否該在此佇足
這裡只有微風輕拂雪花
再也沒有其他聲息

樹林很美,也黝黑且深遠
但我能有諾言尚待履行
還要趕多少路才得以安詳
還要趕多少路才得以安詳

//====2018.03.08====

The Road Not Taken 英文/中文

The Road Not Taken

Two roads diverged in a yellow wood, 
And sorry I could not travel both,
And be one traveler, long I stood,
 And looked down one as far as I could, 
To where it bent in the undergrowth; 

Then took the other, as just as fair, 
And having perhaps the better claim, 
Because it was grassy and wanted wear; 
Though as for that the passing there 
Had worn them really about the same,

 And both that morning equally lay 
In leaves no step had trodden black. 
Oh, I kept the first for another day! 
Yet knowing how way leads on to way, 
I doubted if I should ever come back. 

I shall be telling this with a sigh
Somewhere ages and ages hence: 
Two roads diverged in a wood, and I— 
I took the one less traveled by, 
And that has made all the difference.

//====translation====

未走之路

黃葉林中延伸出了兩條小徑
遺憾的是,我無法同時涉足
身為旅行者,我久久佇足
盡我所能,遠望其中一條的盡頭
直到它隱沒深處

然後我毅然踏上另一條路
或許這條路更值得我嚮往
因為它荒草叢生,人跡罕至
儘管回頭再看兩路
一樣會足跡遍布

那天早晨,兩條小徑都鋪滿落葉
落葉上都沒有被踩踏的痕跡
哦!我把另一條路留給未來
但我知道人世間阡陌縱橫
我不知道未來能否再回到那李

我將會嘆息與敘說
很久很久以後在某個地方
曾有兩條小路在樹林中分手
我選了一條人跡稀少的旅行
這將會有所不同。

//========
2018.03.08