2011/10/11

[C++]求解兩數GCD、LCM (非遞迴)

今天碰到的題目
利用輾轉相除法來做
非遞迴的版本


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int max,min,tmpm,tmpn,temp;
 
    cout << "請輸入第一個數:";
    cin >> max;
    cout << "請輸入第二個數:";
    cin >> min;
 
    if(max < min)
    {
        temp = max;
        max = min;
        min = temp;
    }
 
    tmpm = max;
    tmpn = min;
 
    if(max % min == 0)
    {
        cout << "GCD = " << min << endl;
        cout << "LCM = " << max << endl;
    }
    //
    else
    {
        while(min > 0)
        {
            max = max % min;
            min = min % max;
            if(min == 0)
            {
                cout << "GCD = " << max << endl;
                cout << "LCM = " << max*(tmpm/max)*(tmpn/max) << endl;
            }
        }
    }
 
    system("PAUSE");
    return EXIT_SUCCESS;
}



2011/09/17

Jdownloader在Ubuntu下載完成自動關機

一直忙到今天才發現
hepha前輩在小弟提問之後馬上寫了篇教學文
之前一直沒有辦法解決的AutoShutdown問題終於順利解決了!
十分感謝前輩的協助

教學文網址:
 (手把手玩Linux-Jdownloader下載完畢時自動關機)

2011/08/18

Install Firefox 6.0 On Ubuntu By PPA


Firefox Stable Channel Packages

從上面的URL找到對應的Ubuntu版本
然後將來源加入到source list中

sudo gedit /etc/apt/sources.list

Ubuntu 10.04
deb http://ppa.launchpad.net/mozillateam/firefox-stable/ubuntu lucid main 
deb-src http://ppa.launchpad.net/mozillateam/firefox-stable/ubuntu lucid main 

Ubuntu 10.10
deb http://ppa.launchpad.net/mozillateam/firefox-stable/ubuntu maverick main 
deb-src http://ppa.launchpad.net/mozillateam/firefox-stable/ubuntu maverick main 

Ubuntu 11.04
deb http://ppa.launchpad.net/mozillateam/firefox-stable/ubuntu natty main 
deb-src http://ppa.launchpad.net/mozillateam/firefox-stable/ubuntu natty main 

2011/08/17

[ACM]Q10310 Dog and Gopher

嗯 首先呢 這是Dog&Gopher進階版(其實是誤解題意之下的產物)
上週卡到暑輔考試
 一直沒碰的Dog&Gopher
週末完成結果卡在pow()的用法上 compiler一直不給過...
昨天到學校待了一天 跟著老師Debug 修修補補之後才把原本的bug處理完...
重點是
後來才發現這題其實是不需要讀檔 用cin來寫就可以了(悲劇~~往好處想是多練習了一次開檔案處理???)

 不過這段Code應該還可以更精簡...

原題:http://luckycat.kshs.kh.edu.tw/homework/q10310.htm
測資:下載

2011/08/16

[轉載]ACM初學者中文簡介

ACM Online Judge Guide
介紹ACM線上解題系統的入門須知,方便初學者進入狀況

ACM Online Judge (一樣是說明文)

[c++]簡易剖析範例

#include <iostream>
#include <stdlib.h>

using namespace std;

void Parse(string source,string key)
{
    string Temp = "";
    source = source + key;

    for(int i=0; i<source.length(); i++)
    {
        if(source[i]!= key[0])
        {
            Temp = Temp + source[i];
        }
        else
        {
            cout << Temp << endl;
            Temp = "";
        }
    }
}
int main()
{
    string str;
    string keyword;

    cout << "Please input str:";
    getline(cin,str);
    cout << "Please input keyword:";
    getline(cin,keyword);
    cout << "Parse Result:" << endl;
    Parse(str,keyword);

    return 0;
}