顯示文章

這裡允許您檢視這個會員的所有文章。請注意, 您只能看見您有權限閱讀的文章。


文章 - bunko

頁: [1] 2 3
1
用手敲鍵盤.

2
Windows 討論版 / Re: 公司同仁欲求解KAVO病毒
« 於: 2012-01-17 15:08 »
我覺得不是技術探討,拐彎來發洩情緒,對大家來說浪費了許多時間.

3
IE Only....

白白浪費我的時間.

玩半天後,最後要選參加抽獎時才說,這樣不是整人嗎???

要就一開始就直接說,明明Flash都執行的很正常,就是不讓用Linux搭配Firefox抽獎就對了,
真是太糟糕了.


4
補充一下,也可以用自己產生編號的方式.
輸入跳號測試資料:
代碼: [選擇]
INSERT INTO test0720 VALUES
(18005, '2011-07-16', 7500),
(18015, '2011-07-26', 9000),
(18019, '2011-07-30', 11300);
另外的方式:
代碼: [選擇]
SELECT a.id AS id, a.tdate AS tdate, a.count AS 'count', coalesce(a.count - b.count, a.count) AS diff
FROM ( SELECT @inum := @inum+1 AS anum, i.id, i.tdate, i.count
        FROM (SELECT id, tdate, count
               FROM test0720 ORDER BY id) i,
              (SELECT @inum :=0) r
)a
LEFT JOIN  ( SELECT @jnum := @jnum+1 AS bnum, j.id, j.tdate, j.count
               FROM (SELECT id, tdate, count
                      FROM test0720 ORDER BY id) j,
              (SELECT @jnum :=0) s
)b
ON (b.bnum = a.anum - 1);


+-------+------------+-------+------+
| id    | tdate      | count | diff |
+-------+------------+-------+------+
| 18000 | 2011-07-11 |  2000 | 2000 |
| 18001 | 2011-07-12 |  5000 | 3000 |
| 18002 | 2011-07-13 |  6000 | 1000 |
| 18005 | 2011-07-16 |  7500 | 1500 |
| 18015 | 2011-07-26 |  9000 | 1500 |
| 18019 | 2011-07-30 | 11300 | 2300 |
+-------+------------+-------+------+



使用coalesce()主要是考慮到coalesce()是ANSI-SQL的函數,功能類似IFNULL()

5
database 討論版 / Re: oracle trigger問題一問
« 於: 2011-07-21 18:07 »
before trigger 拿要插入的值來判斷,要用  :New.var 來修飾,這樣才抓的到.

6

CREATE TABLE test0720 (
id INT NOT NULL PRIMARY KEY,
tdate DATE NOT NULL,
count INT NOT NULL
);

INSERT INTO test0720 VALUES
(18000, '2011-07-11', 2000),
(18001, '2011-07-12', 5000),
(18002, '2011-07-13', 6000);


SELECT c.id, c.tdate, c.count, (c.count - 0) AS diff
FROM test0720 c, (SELECT min(id) minid FROM test0720) d
WHERE c.id = d.minid
UNION
SELECT b.id, b.tdate, b.count, b.count - a.count AS diff
FROM test0720 a, test0720 b
WHERE b.id = a.id+1;

+-------+------------+-------+------+
| id    | tdate      | count | diff |
+-------+------------+-------+------+
| 18000 | 2011-07-11 |  2000 | 2000 |
| 18001 | 2011-07-12 |  5000 | 3000 |
| 18002 | 2011-07-13 |  6000 | 1000 |
+-------+------------+-------+------+


7
GTK的人氣越多,Unixer就越倒楣,除了討厭的套件相依性外,大部分看到的Linux only程式都是gtk寫出來的。
然後很多gtk開發者又愛追求最新版,裝個軟體就要整批函式庫都裝進去,只要某個環節沒裝成功,
連帶gnome都要爛了......
以Unixer角度來看,跨平台能力比漂亮的介面更重要,但是Linuxer而言是不會有感覺的(軟體都優先支援Linux)......
等到未來大家都用Linux + GTK時,肉腳也只能無奈了......

嗯~~~"GTK的人氣越多,Unixer就越倒楣."

一語驚醒我夢中人,原來以前參加的是邪惡組織.以前怎麼都沒想到呢...
FreeBSD Devil還有聖獸Tux,都長得蠻可愛的,原來都這麼邪惡.陰謀被你發現了...... ;)

看你骨骼精奇,維護世界和平的重任就靠你了. ;)



8
Linux 討論版 / 回覆: syslog server問題
« 於: 2011-03-04 22:14 »
syslog封包格式中只有分類跟等級再來就是訊息本文了
有個解法是弄一個UDP sniffer接收514 port收到的封包把"來源IP加在訊息本文中"再轉拋到另一台
別使用syslog內建的轉拋功能 :P

http://linux.softpedia.com/get/System/Networking/passlogd-14273.shtml
這裡有一個passlogd,它會sniff 514 port的封包.

passlogd features the following command line options:

-h display this message
-s log captured messages to local syslog
-r reverse lookup ip addresses
-d debug mode
-i ignore packets from
-p listen for syslog packets to (default: 514)
-e set the interface to listen on
-f log to (default: /var/log/passlog)
-S use syslog format in logfile

搭配使用看看.

9
祥如意
惠全家
月高照
步高升

想不到之前寫的一些MySQL的資料,反應還不如這個熱烈... ;D

10
吉祥如意
澤惠全家
明月高照
步步高升

11
官網文件:
http://library.gnome.org/users/evolution/stable/features.html.en

最後一行:
Recall Message function is not available.

看來目前尚未支援.

13
MIS 討論區 / 回覆: ERP廠商維護合約
« 於: 2010-12-28 09:22 »
對方居然說這個是業界常態...所以我對於這個常態保持相當大的懷疑.
----------------------------------------------------------------------------
升級到新版本,中間會有很多很多的地方需要進行修改與測試.
而且需要過來進行升級,需要將原本的資料備份,安裝新系統,導入原本的資料,還有後續的穩定度的測試等等,
事情不少.
這個跟一般的PC升級OS來說,可以說是兩種不同等級的事.
基本上是常態.

14
那篇原本只有一個link,而且是指向本站的.

15
原本有一個link到本站其他篇,就是php版有人問到跟mysql連線的問題.
現在把link拿掉看看.

MySQL Federated storage engine 簡單範例
----------------------------------------
1.環境介紹
  Mysql #1 Name: Akira
  Mysql #2 Name: Bunko

2.首先先在 Akira 裡面建一個叫test1219a的database

create database test1219a;
use test1219a;
grant all on test1219a.* to 'akira'@'%' identified by 'akiraxyz';
flush privileges;
-------------------
然後再用akira登入

建立一個叫Author的Table
akira@[test1219a] Akira
==>CREATE TABLE Author
    -> (AuthorID smallint PRIMARY KEY,
    -> AuthorName varchar(255)
    -> );



3.然後在Bunko 建立一個叫 test1219b的database

create database test1219b;
use test1219b;
grant all on test1219b.* to 'bunko'@'%' identified by 'bunkonao';
flush privileges;
---------------------
接著用bunko登入,建立一個叫 rAuthor的table


bunko@[test1219b] Bunko
==>CREATE TABLE rAuthor
    -> (AuthorID smallint PRIMARY KEY,
    -> AuthorName varchar(255))
    -> engine=FEDERATED
    -> connection='mysql://akira:akiraxyz@192.168.0.100:3307/test1219a/Author';
Query OK, 0 rows affected (0.07 sec)

可以看到上面要指定engine=FEDERATED ,還有連結的資料.包含登入user,password,host ip,port,
database,table組成.

現在select看看...
bunko@[test1219b] Bunko
==>select * from rAuthor;
Empty set (0.01 sec)

空的....正確!因為我們原始的Table也沒有資料.

4.回到Akira

akira@[test1219a] Akira
==>insert into Author values(1, 'Agatha Christie');

akira@[test1219a] Akira
==>select * from Author;
+----------+-----------------+
| AuthorID | AuthorName      |
+----------+-----------------+
|        1 | Agatha Christie |
+----------+-----------------+

已插入一筆資料
--------------------------------------
到Bunko看看

bunko@[test1219b] Bunko
==>select * from rAuthor;
+----------+-----------------+
| AuthorID | AuthorName      |
+----------+-----------------+
|        1 | Agatha Christie |
+----------+-----------------+

可以順利的看到Akira裡面剛加入的資料.
現在我們在Bunko rAuthor新增資料.

bunko@[test1219b] Bunko
==>insert into rAuthor values(2, 'Stephen King');

到Akira

akira@[test1219a] Akira
==>select * from Author;
+----------+-----------------+
| AuthorID | AuthorName      |
+----------+-----------------+
|        1 | Agatha Christie |
|        2 | Stephen King    |
+----------+-----------------+

到此可以看到Akira/Bunko兩個MySQL透過Federated storage engine
讓兩邊都能輕易的存取到實際上存在Akira上的Table.

5. Join

在Bunko裡面,再建立一個新Table : Books

bunko@[test1219b] Bunko
==>CREATE TABLE Books
    -> (BookID smallint NOT NULL AUTO_INCREMENT PRIMARY KEY,
    -> BookName varchar(255),
    -> AuthorID smallint NOT NULL,
    -> INDEX (AuthorID)
    -> );

插入4筆資料:

bunko@[test1219b] Bunko
==>INSERT INTO Books Values(NULL, 'Murder on the Orient Express', 1);

bunko@[test1219b] Bunko
==>INSERT INTO Books Values(NULL, 'Death on the Nile', 1);

bunko@[test1219b] Bunko
==>INSERT INTO Books Values(NULL, 'Different Seasons', 2);

bunko@[test1219b] Bunko
==>INSERT INTO Books Values(NULL, 'The Green Mile', 2);

然後Join

bunko@[test1219b] Bunko
==>SELECT b.BookID,b.BookName,a.AuthorName
    -> FROM Books b, rAuthor a
    -> where b.AuthorID = a.AuthorID;
+--------+------------------------------+-----------------+
| BookID | BookName                     | AuthorName      |
+--------+------------------------------+-----------------+
|      1 | Murder on the Orient Express | Agatha Christie |
|      2 | Death on the Nile            | Agatha Christie |
|      3 | Different Seasons            | Stephen King    |
|      4 | The Green Mile               | Stephen King    |
+--------+------------------------------+-----------------+

基本上到此已經運用Federated storage engine 在一道SQL Command裡面進行
兩個不同MySQL的Join查詢.

6. 補充

回到Akira 用root登入,建立另一個user.只有對 test1219a.Author 有select權限.

root@[test1219a] Akira
==>grant select on test1219a.Author to 'selauthor'@'%' identified by 'authorsel';

root@[test1219a] Akira
==>flush privileges;

---------------------------------------------
一樣在Bunko建立第二個 Table rAuthor2.

bunko@[test1219b] Bunko
==>CREATE TABLE rAuthor2
    -> (AuthorID smallint PRIMARY KEY,
    -> AuthorName varchar(255))
    -> engine=FEDERATED
    -> connection='mysql://selauthor:authorsel@192.168.0.100:3307/test1219a/Author';

bunko@[test1219b] Bunko
==>select * from rAuthor2;
+----------+-----------------+
| AuthorID | AuthorName      |
+----------+-----------------+
|        1 | Agatha Christie |
|        2 | Stephen King    |
+----------+-----------------+


一樣可以查詢.....但是試試看INSERT INTO

bunko@[test1219b] Bunko
==>insert into rAuthor2 values(3, 'Louis Cha');
ERROR 1296 (HY000): Got error 10000 'Error on remote system: 1142: INSERT command denied to user 'selauthor'@'192.168.0.100' for table 'A' from FEDERATED


無法INSERT INTO.這樣就不會改到原始資料了.
兩種方式可以視實際的需求,選擇適當的方式來連線作業.

16
為何發表一篇心得分享,自己都看不到內容..................
就什麼都沒有.廣告文還能在刪除存證區找到.
心得分享卻.....什麼都沒有..........
是系統有狀況嗎?


17
http://phorum.study-area.org/index.php/topic,63768.0.html
討論中,有提到MySQL 一道Query是否能夠跨不同主機來進行查詢呢?
以下是一個簡單的範例,提供大家參考:

MySQL Federated storage engine 簡單範例
----------------------------------------
1.環境介紹
  Mysql #1 Name: Akira
  Mysql #2 Name: Bunko

2.首先先在 Akira 裡面建一個叫test1219a的database

create database test1219a;
use test1219a;
grant all on test1219a.* to 'akira'@'%' identified by 'akiraxyz';
flush privileges;
-------------------
然後再用akira登入

建立一個叫Author的Table
akira@[test1219a] Akira
==>CREATE TABLE Author
    -> (AuthorID smallint PRIMARY KEY,
    -> AuthorName varchar(255)
    -> );



3.然後在Bunko 建立一個叫 test1219b的database

create database test1219b;
use test1219b;
grant all on test1219b.* to 'bunko'@'%' identified by 'bunkonao';
flush privileges;
---------------------
接著用bunko登入,建立一個叫 rAuthor的table


bunko@[test1219b] Bunko
==>CREATE TABLE rAuthor
    -> (AuthorID smallint PRIMARY KEY,
    -> AuthorName varchar(255))
    -> engine=FEDERATED
    -> connection='mysql://akira:akiraxyz@192.168.0.100:3307/test1219a/Author';
Query OK, 0 rows affected (0.07 sec)

可以看到上面要指定engine=FEDERATED ,還有連結的資料.包含登入user,password,host ip,port,
database,table組成.

現在select看看...
bunko@[test1219b] Bunko
==>select * from rAuthor;
Empty set (0.01 sec)

空的....正確!因為我們原始的Table也沒有資料.

4.回到Akira

akira@[test1219a] Akira
==>insert into Author values(1, 'Agatha Christie');

akira@[test1219a] Akira
==>select * from Author;
+----------+-----------------+
| AuthorID | AuthorName      |
+----------+-----------------+
|        1 | Agatha Christie |
+----------+-----------------+

已插入一筆資料
--------------------------------------
到Bunko看看

bunko@[test1219b] Bunko
==>select * from rAuthor;
+----------+-----------------+
| AuthorID | AuthorName      |
+----------+-----------------+
|        1 | Agatha Christie |
+----------+-----------------+

可以順利的看到Akira裡面剛加入的資料.
現在我們在Bunko rAuthor新增資料.

bunko@[test1219b] Bunko
==>insert into rAuthor values(2, 'Stephen King');

到Akira

akira@[test1219a] Akira
==>select * from Author;
+----------+-----------------+
| AuthorID | AuthorName      |
+----------+-----------------+
|        1 | Agatha Christie |
|        2 | Stephen King    |
+----------+-----------------+

到此可以看到Akira/Bunko兩個MySQL透過Federated storage engine
讓兩邊都能輕易的存取到實際上存在Akira上的Table.

5. Join

在Bunko裡面,再建立一個新Table : Books

bunko@[test1219b] Bunko
==>CREATE TABLE Books
    -> (BookID smallint NOT NULL AUTO_INCREMENT PRIMARY KEY,
    -> BookName varchar(255),
    -> AuthorID smallint NOT NULL,
    -> INDEX (AuthorID)
    -> );

插入4筆資料:

bunko@[test1219b] Bunko
==>INSERT INTO Books Values(NULL, 'Murder on the Orient Express', 1);

bunko@[test1219b] Bunko
==>INSERT INTO Books Values(NULL, 'Death on the Nile', 1);

bunko@[test1219b] Bunko
==>INSERT INTO Books Values(NULL, 'Different Seasons', 2);

bunko@[test1219b] Bunko
==>INSERT INTO Books Values(NULL, 'The Green Mile', 2);

然後Join

bunko@[test1219b] Bunko
==>SELECT b.BookID,b.BookName,a.AuthorName
    -> FROM Books b, rAuthor a
    -> where b.AuthorID = a.AuthorID;
+--------+------------------------------+-----------------+
| BookID | BookName                     | AuthorName      |
+--------+------------------------------+-----------------+
|      1 | Murder on the Orient Express | Agatha Christie |
|      2 | Death on the Nile            | Agatha Christie |
|      3 | Different Seasons            | Stephen King    |
|      4 | The Green Mile               | Stephen King    |
+--------+------------------------------+-----------------+

基本上到此已經運用Federated storage engine 在一道SQL Command裡面進行
兩個不同MySQL的Join查詢.

6. 補充

回到Akira 用root登入,建立另一個user.只有對 test1219a.Author 有select權限.

root@[test1219a] Akira
==>grant select on test1219a.Author to 'selauthor'@'%' identified by 'authorsel';

root@[test1219a] Akira
==>flush privileges;

---------------------------------------------
一樣在Bunko建立第二個 Table rAuthor2.

bunko@[test1219b] Bunko
==>CREATE TABLE rAuthor2
    -> (AuthorID smallint PRIMARY KEY,
    -> AuthorName varchar(255))
    -> engine=FEDERATED
    -> connection='mysql://selauthor:authorsel@192.168.0.100:3307/test1219a/Author';

bunko@[test1219b] Bunko
==>select * from rAuthor2;
+----------+-----------------+
| AuthorID | AuthorName      |
+----------+-----------------+
|        1 | Agatha Christie |
|        2 | Stephen King    |
+----------+-----------------+


一樣可以查詢.....但是試試看INSERT INTO

bunko@[test1219b] Bunko
==>insert into rAuthor2 values(3, 'Louis Cha');
ERROR 1296 (HY000): Got error 10000 'Error on remote system: 1142: INSERT command denied to user 'selauthor'@'192.168.0.100' for table 'A' from FEDERATED


無法INSERT INTO.
可以視實際的需求,選擇適當的方式來連線作業.

18
DPMS : Display Power Management Signaling


XSET
DESCRIPTION
       This program is used to set various user preference options of the dis-
       play.


xset

        -dpms   The -dpms option disables DPMS (Energy Star) features.

       +dpms   The +dpms option enables DPMS (Energy Star) features.

       dpms flags...
               The dpms option allows the DPMS (Energy Star) parameters to  be
               set.   The option can take up to three numerical values, or the
               ‘force’ flag followed by  a  DPMS  state.   The  ‘force’  flags
               forces the server to immediately switch to the DPMS state spec-
               ified.  The DPMS state can  be  one  of  ‘standby’,  ‘suspend’,
               ‘off’,  or ‘on’.  When numerical values are given, they set the
               inactivity period (in units of seconds) before the three  modes
               are  activated.   The  first  value  given is for the ‘standby’
               mode, the second is for the ‘suspend’ mode, and  the  third  is
               for  the  ‘off’  mode.  Setting these values implicitly enables
               the DPMS features.  A value of zero disables a particular mode.


19
肉腳版 / 回覆: (不用迴圈)求完全數
« 於: 2010-12-15 14:26 »
代碼: (c) [選擇]
// Find Pefect Number and Calculate CPU Time   

#include <stdio.h>
#include <time.h>

unsigned long long mkperf(unsigned int n);
int is_perfect(unsigned long long p);
char* get_time(void);

int main(int argc, char **argv)
{
unsigned int i, count = 0;
unsigned long long perf,last, r;
unsigned long long num[34];
unsigned long long pb[34];
int cheat[8] = {0, 1, 2, 4, 8, 11, 13, 22};
clock_t start, end, shstart, shend;
double cpu_time_used;

last = 1;

for(i=1; i <= 33; i++) {
perf = mkperf(i);
if ( perf >= last) {
// printf("i=%2d perf=%20llu\n", i, perf);
num[i] = perf;
} else {
printf("****over in i=%2d perf=%20llu\n", i, perf);
break;
}
last = perf;
}

for(i=1; i <= 33; i++) {
r = num[i] % 10;
if ( r == 6 || r == 8) {
printf("maybe is a perfect number:%20Lu\n", num[i]);
pb[count++] = num[i];
}
}

printf("Count = %u\n", count);
printf("will check these numbers\n");
for(i=0; i<=5; i++) {
printf("%20Lu\n", pb[cheat[i]]);
}

printf("---- Checking ----\n");
printf("Start at %s\n", get_time());
start = clock();
// Checking Loop [START]
for(i=0; i <= 5; i++) {
shstart = clock();
if( is_perfect(pb[cheat[i]]) ) {
shend = clock();
cpu_time_used = ((double) (shend - shstart)) / CLOCKS_PER_SEC;
printf("%20Lu is perfect number\n", pb[cheat[i]]);
printf("at %s CPU Time Used:%f\n", get_time(), cpu_time_used);
}
}
// Checking Loop [END]
end = clock();
printf("End   at %s\n", get_time());
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("CPU Time Used = %f\n", cpu_time_used);



return 0;
}

unsigned long long mkperf(unsigned int n)
{ //
unsigned long long p=1;
p <<= n;
p--;
p <<= (n-1);
return p;
}


int is_perfect(unsigned long long p)
{
unsigned long long i, sum;
sum = 0;
for(i=1; i <= (p/2); i++) {
if((p % i) == 0) {
sum += i;
}
}
if( sum == p) {
return 1;
} else {
return 0;
}
}

char* get_time(void)
{
time_t timeval;

(void)time(&timeval);
return ctime(&timeval);
}

--------------------------------------------------
執行結果:
maybe is a perfect number:                   6
maybe is a perfect number:                  28
maybe is a perfect number:                 496
maybe is a perfect number:                2016
maybe is a perfect number:                8128
maybe is a perfect number:              130816
maybe is a perfect number:              523776
maybe is a perfect number:             2096128
maybe is a perfect number:            33550336
maybe is a perfect number:           134209536
maybe is a perfect number:           536854528
maybe is a perfect number:          8589869056
maybe is a perfect number:         34359607296
maybe is a perfect number:        137438691328
maybe is a perfect number:       2199022206976
maybe is a perfect number:       8796090925056
maybe is a perfect number:      35184367894528
maybe is a perfect number:     562949936644096
maybe is a perfect number:    2251799780130816
maybe is a perfect number:    9007199187632128
maybe is a perfect number:  144115187807420416
maybe is a perfect number:  576460751766552576
maybe is a perfect number: 2305843008139952128
Count = 23
will check these numbers
                   6
                  28
                 496
                8128
            33550336
          8589869056
---- Checking ----
Start at Wed Dec 15 14:17:48 2010

                   6 is perfect number
at Wed Dec 15 14:17:48 2010
 CPU Time Used:0.000000
                  28 is perfect number
at Wed Dec 15 14:17:48 2010
 CPU Time Used:0.000000
                 496 is perfect number
at Wed Dec 15 14:17:48 2010
 CPU Time Used:0.000000
                8128 is perfect number
at Wed Dec 15 14:17:48 2010
 CPU Time Used:0.000000
            33550336 is perfect number
at Wed Dec 15 14:17:49 2010
 CPU Time Used:0.420000
          8589869056 is perfect number
at Wed Dec 15 14:19:52 2010
 CPU Time Used:121.840000
End   at Wed Dec 15 14:19:52 2010

CPU Time Used = 122.260000

受限於系統的CPU/與unsigned long long的大小,所以能運算的有限制,而且後面的要花很多時間.
故計算到8589869056.第53行可以改一下i的上限,就會多驗算了.

20
肉腳版 / 回覆: (不用迴圈)求完全數
« 於: 2010-12-08 20:33 »
$gcc -Wall -lm  perfect4.c -o perfect4

這樣編譯......裡面那個 -lm 就是把數學函數包進來.

這個程式可以算出第五個沒問題,但是後面的話......我有留個bug......
你試試看,也可以看看是哪邊有bug.
我都是用迴圈......
那句話我沒表達的很好,造成你誤會了,你就先不管它囉...
這個程式不會跑很久,因為它只有挑一些來算.

21
肉腳版 / 回覆: (不用迴圈)求完全數
« 於: 2010-12-07 18:18 »
代碼: (c) [選擇]
//      perfect4.c

#include <stdio.h>
#include <math.h>
int main(int argc, char **argv)
{
unsigned long long pa[12];
unsigned long long sum,i;
double n;
int j=0,count=0;

for(n=2.0; n <= 13.0; n++) {
pa[j++] = (unsigned long long) pow(2.0, (n-1.0)) * (pow(2.0, n) - 1.0);

}

for(j=0; j <= 11; j++) {

printf("it maybe is a perfect number:%llu\n", pa[j]);
}
printf("=================================================\n");
printf("The real perfect numbers:\n");
count = 0;
for(j=0; j <= 11; j++) {
sum = 0;
for(i=1; i <= (pa[j]/2); i++) {
if((pa[j] % i) == 0) {
sum += i;
}
}
if( sum == pa[j]) {

printf("\n#%d perfect number: %20llu\n",++count, pa[j]);
}
}

return 0;
}

----------------------------
編譯時一樣記得把math包含進來.
先用公式計算,然後存到array, 然後取出array內的可能為perfect number的值,再用暴力法驗算,驗算符合後印出來.
可是....還是用迴圈快多了....

$gcc -Wall -lm  perfect4.c -o perfect4
$ ./perfect4
it maybe is a perfect number:6
it maybe is a perfect number:28
it maybe is a perfect number:120
it maybe is a perfect number:496
it maybe is a perfect number:2016
it maybe is a perfect number:8128
it maybe is a perfect number:32640
it maybe is a perfect number:130816
it maybe is a perfect number:523776
it maybe is a perfect number:2096128
it maybe is a perfect number:8386560
it maybe is a perfect number:33550336
=================================================
The real perfect numbers:

#1 perfect number:                    6

#2 perfect number:                   28

#3 perfect number:                  496

#4 perfect number:                 8128

#5 perfect number:             33550336



22
肉腳版 / 回覆: (不用迴圈)求完全數
« 於: 2010-12-07 17:29 »
另一個用公式算的.

//      perfect3.c
//      
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv)
{
   unsigned long long perf;
   double i;
   
   for(i=2.0; i <= 13.0; i++) {
      perf = (unsigned long long) pow(2.0, (i-1.0)) * (pow(2.0, i) - 1.0);
      printf("it maybe is a perfect number:%llu\n", perf);
   }
   return 0;
}
-------------------------------------------
編譯時要引入math函數庫.
$ gcc -Wall -lm  perfect3.c -o perfect3

$ ./perfect3
it maybe is a perfect number:6
it maybe is a perfect number:28
it maybe is a perfect number:120
it maybe is a perfect number:496
it maybe is a perfect number:2016
it maybe is a perfect number:8128
it maybe is a perfect number:32640
it maybe is a perfect number:130816
it maybe is a perfect number:523776
it maybe is a perfect number:2096128
it maybe is a perfect number:8386560
it maybe is a perfect number:33550336

32640到8386560 都不是, 33550336 才是真正第五個完全數.

參考一下囉~~~ :) 另外上面那個呆呆一直算的程式,只要把一部分程式碼搬動一下,就不會多算一些數字出來了.

23
肉腳版 / 回覆: (不用迴圈)求完全數
« 於: 2010-12-07 13:47 »
//      perfect_number.c
//  Perfect Numbers under 10000
#include <stdio.h>

int main(int argc, char **argv)
{
   int a, i, sum;
   printf("This Program will show Perfect Numbers under 10000:\n");
   
   for(a=1; a <= 10000; a++) {
      sum = 0;
      for(i=1; i <= (a / 2) ; i++) {
         if((a % i) == 0) {
            sum += i;
            if( sum == a) {
               printf("perfect number: %4d\n", a);
               break;
            }
         }
      }
   }
   printf("---------------------\n");
   printf("Done!\n");
   return 0;
}


我只會用迴圈來解.......執行結果如下:
This Program will show Perfect Numbers under 10000:
perfect number:    6
perfect number:   24
perfect number:   28
perfect number:  496
perfect number: 2016
perfect number: 8128
perfect number: 8190
---------------------
Done!

補充說明,剛剛看了一下perfect number的定義,我這個程式列出來的沒有符合perfect number的定義.
24 不是2016也不是,8128是.8190也不是.........
===============================
底下是另一個,可以找比較多數字的........但是還是會多找出一些東西

#include <stdio.h>
#include <limits.h>
int main(int argc, char **argv)
{
   int running = 1,count,p;
   unsigned long long a, i, sum;
   printf("This Program can find Perfect Numbers under %llu:\n", ULLONG_MAX );
   printf("How many Pefect Numbers you want to find?");
   scanf("%i", &p);
   a = 0; count=0;
   while(running) {
      a += 2;
      
      if( a >= ULLONG_MAX) {
         running = 0;
      }
      sum = 0;
      for(i=1; i <= (a / 2) ; i++) {
         if((a % i) == 0) {
            sum += i;
            if( sum == a) {
               count++;
               printf("#%d perfect number: %20llu\n",count, a);
               
               if( count == p) {
                  running = 0;
               }
               break;
            }
         }
      }
   }
   printf("---------------------\n");
   printf("Done!\n");
   return 0;
}

-------------------------------------




24
Hi Newbie,

ifconfig on the /sbin

要用root才能執行.不需改任何設定,這是正常的. :)

要是能使用才要擔心.

25
不知道符不符合你的需求, ApacheBench

http://httpd.apache.org/docs/2.2/programs/ab.html

Google一下 ApacheBench 能看到更多相關資料

26
不好意思再請問一下

我想將etc.tar這個壓縮檔丟到192.168.0.100的E槽

tar xvf etc.tar -C 192.168.0.100 E:\

指令好像有錯,請問可以怎麼做修正?

你這指令是在哪裡執行的?? 有什麼錯誤訊息??
以後最好是要把這些資訊補清楚比較好.

我猜測你是在Linux上壓縮(tar),現在想要用tar解開直接放到windows(192.168.0.100),這樣對嗎?若是要這樣,樓上Tommy大已經說明了,samba.
若是沒裝samba的話,可以使用ftp或是winscp (http://winscp.net/eng/docs/lang:cht) , 將檔案傳到windows這邊,然後用能解tar的軟體(7z,winrar...)
來解開.


27
rsync 也有一些程式可以在windows上跑.
DeltaCopy
http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp
QtdSync
http://qtdtools.doering-thomas.de/page.php?seite=0&sub=1&lang=en
Syncrify
http://web.synametrics.com/syncrify.htm
Cwrsync
http://www.itefix.no/i2/node/10650

其實蠻多的,google rsync windows 就會出現一堆了,還有一堆網誌有說明步驟.

自己多試試,最好是能夠將使用心得整理好跟大家分享,而不要當免洗帳號,問完問題就閃了.
以上建議提供你參考.

28
會不會是這個地方呢??? 先確定一下目錄權限.

1.2 在OS中建立目錄供MySQL存取,並建立預備輸入的文字檔

ps. 目錄必須設定讓mysql有權限讀寫,不一定是讓mysql當owner

# cd /
# mkdir myimpexp
# chown mysql:mysql myimpexp

上面這段部份有漏掉嗎??

或是這段 file 權限的賦予有漏掉嗎?
root@[(none)]>grant file on *.* to 'sorter'@'%';

---------------------------------------------------------------------------
另外那個例子是在0902,而後面的一些程式碼是會以日期方式來決定檔名.
後面的部份就要注意一下作相對應的調整.

29
有些書上的範例是比較舊一些,所以你在實作時會因為編譯器版本較新,要作適當的修正.
Linux上面的程式設計有些書是很經典的,名氣也很大.
http://www.advancedlinuxprogramming.com/ 
這裡就能download了.
另外可以看這本:
http://www.books.com.tw/exep/prod/booksfile.php?item=0010418239

中文版我是沒看過啦,但是我想中文版應該可以讓初學者上手較快.裡面有mysql的例子,應該對你有幫助.

當然C的經典K&R, W.Richard Stevens的經典Advanced Programming in the Unix Environment (簡稱APUE,在一些討論中就直接寫APUE代表本書).
http://www.books.com.tw/exep/prod/booksfile.php?item=0010229690

另外這是大陸翻譯的,還是W.Richard Stevens的經典著作,不過大陸翻譯的.....我一向很受不了....
http://www.books.com.tw/exep/prod/china/chinafile.php?item=CN10398779

若是英文閱讀還可以,最好是看英文版的,或是對照著讀.
另外說明一下,書你要多找幾家比價(我只是去那家網站舉例而已),或是先到書店去翻看一下.
當這幾本一起研讀時,你還需要什麼書,應該自己心裡就有譜了.所以也不一下推薦太多,以免混亂.
加油囉~~~ :)

30
bzero() 要#include<strings.h> , 不是#incldue<string.h> , 你看的那程式編排可能有出錯.
因為用 #include<string.h> 會很自然習慣.
另外bzero()屬於比較舊的了,最好是改用 memset(),以你的例子就是改為 memset(&newtio, '\0',sizeof(newtio));
一樣是將資料做基本設定.

至於exit(), 要#include<stdlib.h>, 這樣才能用......
改成 exit(EXIT_FAILURE); 可讀性會高一些.

你參考的資料可能與你使用的環境不同,還是編排有漏掉一些東西吧.你再試看看.

頁: [1] 2 3