2012/05/26
install oracle-java on Ubuntu via PPA
找到比較方便的作法
利用PPA來源
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
完成後用java-version來看看java是否已經替換成oracle java 7了
2012/05/20
刪除Ubuntu磁區後修復Windwos mbr
如果直接在Windwos底下的磁碟管理工具將Ubuntu所在磁區刪除
下次開機就會碰到GRUB無法抓到分割區的問題
如果要Windows正常運作
以Windows 7為例
用Windows 7安裝光碟開機
選擇修復選項
在命令提示字元中輸入
bootsect /nt60 SYS /mbr
接著重新開機即可
參考:http://ahhafree.blogspot.com/2011/11/ubuntu-grub-rescue.html
下次開機就會碰到GRUB無法抓到分割區的問題
如果要Windows正常運作
以Windows 7為例
用Windows 7安裝光碟開機
選擇修復選項
在命令提示字元中輸入
bootsect /nt60 SYS /mbr
接著重新開機即可
參考:http://ahhafree.blogspot.com/2011/11/ubuntu-grub-rescue.html
[C++]猜數字
C++寫的猜數字程式
猜一個四位數字(千位數不為0,且沒有數字重複)
它會提示有幾A幾B
ex: 2A1B
2A代表有2個數值猜對且位置正確
1B代表有1個數值猜對但位置不正確
以下為code
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <time.h>
using namespace std;
//把整數轉為字串的副程式IntToString
string IntToString (int N)
{
string Get;
stringstream ss;
ss << N;
ss >> Get;
return Get;
}
int main()
{
string Answer; //儲存答案
string Guess; //儲存使用者猜的數字
int Num; //儲存由rand()產生的亂數
int A = 0;
int B = 0;
int Time = 5; //一個回合可以猜的次數
int Round = 1; //回合數 初始值 = 1
srand(time(NULL));
while(true)
{
Answer = IntToString(rand()%9+1); //先將答案的千位數字指定為1~9之間的任意數字
for (int i=1; i<4; i++)
{
//產生謎底
Num = rand()%10;
if(Answer.find(IntToString(Num)) == -1)
{
Answer = Answer + IntToString(Num);
}
else
{
i--;
}
}
cout << "----------------------" << endl;
cout << "Round " << Round << endl; //提示目前回合
cout << endl;
while(true)
{
//將A與B值初始化
A = 0;
B = 0;
//使用者猜數字
cout << "請猜一個四位數字: ";
getline(cin,Guess);
//判斷幾A幾B
for (int i=0; i<4; i++)
{
for (int j=0; j<4; j++)
{
if((Answer[i] == Guess[j])&&(i == j))
{
A++; //值吻合且位置相同
}
else if((Answer[i] == Guess[j])&&(i != j))
{
B++; //值吻合但位置不同
}
}
}
//輸出提示
if (A == 4)
{
cout << "恭喜答對!" << endl;
break;
}
else if((A != 4)&&(Time > 1))
{
Time--;
cout << A << "A" << B << "B" << endl;
cout << "尚餘 " << Time << " 次機會..." << endl;
cout << endl;
//Debug過程用
//cout << Answer << endl;
}
else
{
break;
}
}
//
cout << A << "A" << B << "B" << endl;
cout << endl;
cout << "正確解答: " << Answer << endl;
Round++;
Answer = "";
Guess = "";
Time = 5;
}
return 0;
}
猜一個四位數字(千位數不為0,且沒有數字重複)
它會提示有幾A幾B
ex: 2A1B
2A代表有2個數值猜對且位置正確
1B代表有1個數值猜對但位置不正確
以下為code
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <time.h>
using namespace std;
//把整數轉為字串的副程式IntToString
string IntToString (int N)
{
string Get;
stringstream ss;
ss << N;
ss >> Get;
return Get;
}
int main()
{
string Answer; //儲存答案
string Guess; //儲存使用者猜的數字
int Num; //儲存由rand()產生的亂數
int A = 0;
int B = 0;
int Time = 5; //一個回合可以猜的次數
int Round = 1; //回合數 初始值 = 1
srand(time(NULL));
while(true)
{
Answer = IntToString(rand()%9+1); //先將答案的千位數字指定為1~9之間的任意數字
for (int i=1; i<4; i++)
{
//產生謎底
Num = rand()%10;
if(Answer.find(IntToString(Num)) == -1)
{
Answer = Answer + IntToString(Num);
}
else
{
i--;
}
}
cout << "----------------------" << endl;
cout << "Round " << Round << endl; //提示目前回合
cout << endl;
while(true)
{
//將A與B值初始化
A = 0;
B = 0;
//使用者猜數字
cout << "請猜一個四位數字: ";
getline(cin,Guess);
//判斷幾A幾B
for (int i=0; i<4; i++)
{
for (int j=0; j<4; j++)
{
if((Answer[i] == Guess[j])&&(i == j))
{
A++; //值吻合且位置相同
}
else if((Answer[i] == Guess[j])&&(i != j))
{
B++; //值吻合但位置不同
}
}
}
//輸出提示
if (A == 4)
{
cout << "恭喜答對!" << endl;
break;
}
else if((A != 4)&&(Time > 1))
{
Time--;
cout << A << "A" << B << "B" << endl;
cout << "尚餘 " << Time << " 次機會..." << endl;
cout << endl;
//Debug過程用
//cout << Answer << endl;
}
else
{
break;
}
}
//
cout << A << "A" << B << "B" << endl;
cout << endl;
cout << "正確解答: " << Answer << endl;
Round++;
Answer = "";
Guess = "";
Time = 5;
}
return 0;
}
2012/05/02
[C++]跑馬燈改版
電腦課實做
隨手弄弄的作品...
就...橫桿轉呀轉的同時顯示進度...
#include <cstdlib>
#include <iostream>
using namespace std;
void Delay()
{
for(int i=0; i<60000000; i++)
{
//用於時間延遲的副程式
}
}
int main(int argc, char *argv[])
{
for(int i=1; i<=100; i++)
{
if(i % 4 == 0)
{
cout << "|" << " . " << i << "%";
}
else if(i % 4 == 1)
{
cout << "/" << " .. " << i << "%";
}
else if(i % 4 == 2)
{
cout << "─" << " ... " << i << "%";
}
else if(i % 4 == 3)
{
cout << "\" << " .... " << i << "%";
}
Delay();
system("CLS");
}
system("PAUSE");
return EXIT_SUCCESS;
}
隨手弄弄的作品...
就...橫桿轉呀轉的同時顯示進度...
#include <cstdlib>
#include <iostream>
using namespace std;
void Delay()
{
for(int i=0; i<60000000; i++)
{
//用於時間延遲的副程式
}
}
int main(int argc, char *argv[])
{
for(int i=1; i<=100; i++)
{
if(i % 4 == 0)
{
cout << "|" << " . " << i << "%";
}
else if(i % 4 == 1)
{
cout << "/" << " .. " << i << "%";
}
else if(i % 4 == 2)
{
cout << "─" << " ... " << i << "%";
}
else if(i % 4 == 3)
{
cout << "\" << " .... " << i << "%";
}
Delay();
system("CLS");
}
system("PAUSE");
return EXIT_SUCCESS;
}
訂閱:
文章 (Atom)