史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2006-12-28, 10:53 AM   #1
Chin-Wei 帥哥
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設 討論 - 二道問題考考大家

老是在回答 FAQ 等級的問題大家應該也會膩吧 ^^a
今天小老弟就出二道題目考考大家~ 一起來歡樂吧(?)

不限任何程式語言,歡迎大家來挑戰,雖然就算解出來了也沒獎品就是了 = =a



第一大題:
請分析下列文章中的各個英文單字出現的頻率,並將出現頻率最高的三個單字輸出至螢幕。
輸出格式為: 頻率<TAB or Space>單字

引用:
WASHINGTON - Gerald R. Ford was a man of limited ambition who, through bizarre circumstances never before experienced by the country, achieved an office that others win through the greatest determination and calculation. The nation's 38th president, Ford wanted only to become speaker of the House. History had another place for him. ADVERTISEMENT Ford was comfortable in the House, representing a Michigan congressional district for 25 years, rising to Republican leader and working toward his dream of one day running the chamber, when President Nixon called.He needed a new vice president; scandal had chased Spiro Agnew from the office.Ford wasn't Nixon's first choice, but the president agreed that the amiable Republican would be the easiest to win confirmation by both houses of Congress. So it went, and Ford became vice president in December 1973.Yet eight months later, the scenario got even stranger.




第二大題:
uucp:x:12:14:Adrian W. Jones/OFFICE_01/TEL_NUM_01
operator:x:13:0:Dorothy Gale/OFFICE_02/TEL_NUM_02
games:x:12:140:John Hancock/OFFICE_03/TEL_NUM_03

請將上述資料紅色的部份,擷取並輸出至暫存檔(eg.tmp.txt),內容為:
Gale, Dorothy   <TAB>OFFICE_02<TAB>TEL_NUM_02
Hancock, John  <TAB>OFFICE_03<TAB>TEL_NUM_03
Jones, Adrian W. <TAB>OFFICE_01<TAB>TEL_NUM_01
(必須依照人名順序排列)



==
解不出來要打屁屁喔~都很簡單的ㄋㄟ~
我當然知道怎麼解不然我哪敢問
__________________
思考,正是從一個錯誤,跳進另外一個錯誤。
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
向 Chin-Wei 送花的會員:
Admin2 (2006-12-28)
感謝您發表一篇好文章
舊 2006-12-28, 03:12 PM   #2 (permalink)
協調管理員
 
飛鳥 的頭像
榮譽勳章
UID - 23073
在線等級: 級別:72 | 在線時長:5513小時 | 升級還需:108小時級別:72 | 在線時長:5513小時 | 升級還需:108小時
註冊日期: 2003-01-07
VIP期限: 無限期
住址: 史萊姆團隊
文章: 7199
精華: 11
現金: 837 金幣
資產: 260029 金幣
預設

先做一題的一部份
有空再繼續


使用perl寫,可在windows及linux下 running
perl程式:
引用:
#!/usr/bin/perl

print "請輸入要分析英文單字出現的頻率:";
my $line=<>; #從標準輸入,放入變數$line
print "\n";
chomp $line; #去除輸入最後的換行字元
$line=~s/\,/ /g; #符號整理
$line=~s/\./ /g; #符號整理
$line=~s/\!/ /g; #符號整理
$line=~s/\?/ /g; #符號整理
$line=~s/\;/ /g; #符號整理
$line=~s/\:/ /g; #符號整理
$line=~s/\"/ /g; #符號整理
$line=~s/\'/ /g; #符號整理
$line=~s/ / /g; #整理多餘空白鍵
$line=~s/ / /g; #整理多餘空白鍵

my @arrr;
@arrr=split(/ / , $line); #把文章,以空白鍵作分開單字的關鍵,放入陣列中


my @repeat;

for (my $i=0;$arrr[$i];$i++){

for (my $j=0;$arrr[$j];$j++){
$repeat[$i][0] = $arrr[$i];
$repeat[$i][1] = $repeat[$i][1] + 1 if ($arrr[$i] eq $arrr[$j]); #比對單字,出現一次寫入$repeat二維陣列中
}

}

#print出所有單字出現的次數
for (my $i=0;$arrr[$i];$i++){
print "$arrr[$i] 出現了 $repeat[$i][1] 次\n";
}




$line=<>;
執行結果:
引用:
請輸入要分析英文單字出現的頻率:WASHINGTON - Gerald R. Ford was a man of limited
ambition who, through bizarre circumstances never before experienced by the cou
ntry, achieved an office that others win through the greatest determination and
calculation. The nation's 38th president, Ford wanted only to become speaker of
the House. History had another place for him. ADVERTISEMENT Ford was comfortabl
e in the House, representing a Michigan congressional district for 25 years, ris
ing to Republican leader and working toward his dream of one day running the cha
mber, when President Nixon called.He needed a new vice president; scandal had ch
ased Spiro Agnew from the office.Ford wasn't Nixon's first choice, but the presi
dent agreed that the amiable Republican would be the easiest to win confirmation
by both houses of Congress. So it went, and Ford became vice president in Decem
ber 1973.Yet eight months later, the scenario got even stranger.

WASHINGTON 出現了 1 次
- 出現了 1 次
Gerald 出現了 1 次
R 出現了 1 次
Ford 出現了 4 次
was 出現了 2 次
a 出現了 3 次
man 出現了 1 次
of 出現了 4 次
limited 出現了 1 次
ambition 出現了 1 次
who 出現了 1 次
through 出現了 2 次
bizarre 出現了 1 次
circumstances 出現了 1 次
never 出現了 1 次
before 出現了 1 次
experienced 出現了 1 次
by 出現了 2 次
the 出現了 10 次
country 出現了 1 次
achieved 出現了 1 次
an 出現了 1 次
office 出現了 2 次
that 出現了 2 次
others 出現了 1 次
win 出現了 2 次
through 出現了 2 次
the 出現了 10 次
greatest 出現了 1 次
determination 出現了 1 次
and 出現了 3 次
calculation 出現了 1 次
The 出現了 1 次
nation 出現了 1 次
s 出現了 2 次
38th 出現了 1 次
president 出現了 4 次
Ford 出現了 4 次
wanted 出現了 1 次
only 出現了 1 次
to 出現了 3 次
become 出現了 1 次
speaker 出現了 1 次
of 出現了 4 次
the 出現了 10 次
House 出現了 2 次
History 出現了 1 次
had 出現了 2 次
another 出現了 1 次
place 出現了 1 次
for 出現了 2 次
him 出現了 1 次
ADVERTISEMENT Ford 出現了 1 次
was 出現了 2 次
comfortable 出現了 1 次
in 出現了 2 次
the 出現了 10 次
House 出現了 2 次
representing 出現了 1 次
a 出現了 3 次
Michigan 出現了 1 次
congressional 出現了 1 次
district 出現了 1 次
for 出現了 2 次
25 出現了 1 次
years 出現了 1 次
rising 出現了 1 次
to 出現了 3 次
Republican 出現了 2 次
leader 出現了 1 次
and 出現了 3 次
working 出現了 1 次
toward 出現了 1 次
his 出現了 1 次
dream 出現了 1 次
of 出現了 4 次
one 出現了 1 次
day 出現了 1 次
running 出現了 1 次
the 出現了 10 次
chamber 出現了 1 次
when 出現了 1 次
President 出現了 1 次
Nixon 出現了 2 次
called 出現了 1 次
He 出現了 1 次
needed 出現了 1 次
a 出現了 3 次
new 出現了 1 次
vice 出現了 2 次
president 出現了 4 次
scandal 出現了 1 次
had 出現了 2 次
chased 出現了 1 次
Spiro 出現了 1 次
Agnew 出現了 1 次
from 出現了 1 次
the 出現了 10 次
office 出現了 2 次
Ford 出現了 4 次
wasn 出現了 1 次
t 出現了 1 次
Nixon 出現了 2 次
s 出現了 2 次
first 出現了 1 次
choice 出現了 1 次
but 出現了 1 次
the 出現了 10 次
president 出現了 4 次
agreed 出現了 1 次
that 出現了 2 次
the 出現了 10 次
amiable 出現了 1 次
Republican 出現了 2 次
would 出現了 1 次
be 出現了 1 次
the 出現了 10 次
easiest 出現了 1 次
to 出現了 3 次
win 出現了 2 次
confirmation 出現了 1 次
by 出現了 2 次
both 出現了 1 次
houses 出現了 1 次
of 出現了 4 次
Congress 出現了 1 次
So 出現了 1 次
it 出現了 1 次
went 出現了 1 次
and 出現了 3 次
Ford 出現了 4 次
became 出現了 1 次
vice 出現了 2 次
president 出現了 4 次
in 出現了 2 次
December 出現了 1 次
1973 出現了 1 次
Yet 出現了 1 次
eight 出現了 1 次
months 出現了 1 次
later 出現了 1 次
the 出現了 10 次
scenario 出現了 1 次
got 出現了 1 次
even 出現了 1 次
stranger 出現了 1 次
先這樣,忙一下,前三名等等再用
__________________
http://flybird017.googlepages.com/quok.gif http://flybird020.googlepages.com/new321.gif
寶貝你我的地球
, 請 少開電器,減少溫室氣體排放外,多種植植物,減少列印, 多用背面,丟棄時做垃圾分類。

http://netgames123.googlepages.com/tobikeways.jpg

飛鳥 目前離線  
送花文章: 11706, 收花文章: 3363 篇, 收花: 16453 次
回覆時引用此帖
舊 2006-12-28, 09:44 PM   #3 (permalink)
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設

引用:
作者: 飛鳥
#!/usr/bin/perl

print "請輸入要分析英文單字出現的頻率:";
my $line=<>; #從標準輸入,放入變數$line
print "\n";
chomp $line; #去除輸入最後的換行字元
$line=~s/\,/ /g; #符號整理
$line=~s/\./ /g; #符號整理
$line=~s/\!/ /g; #符號整理
$line=~s/\?/ /g; #符號整理
$line=~s/\;/ /g; #符號整理
$line=~s/\:/ /g; #符號整理
$line=~s/\"/ /g; #符號整理
$line=~s/\'/ /g; #符號整理
$line=~s/ / /g; #整理多餘空白鍵
$line=~s/ / /g; #整理多餘空白鍵

my @arrr;
@arrr=split(/ / , $line); #把文章,以空白鍵作分開單字的關鍵,放入陣列中


my @repeat;

for (my $i=0;$arrr[$i];$i++){

for (my $j=0;$arrr[$j];$j++){
$repeat[$i][0] = $arrr[$i];
$repeat[$i][1] = $repeat[$i][1] + 1 if ($arrr[$i] eq $arrr[$j]); #比對單字,出現一次寫入$repeat二維陣列中
}

}

#print出所有單字出現的次數
for (my $i=0;$arrr[$i];$i++){
print "$arrr[$i] 出現了 $repeat[$i][1] 次\n";
}

$line=<>;

Perl 不愧是用來處理字串專用的程式語言,能夠在這麼短短的幾行就解決確實名不虛傳
阿鳥老大 BASH 熟嗎?BASH 熟的話在處理很多東西會很方便喔~ ^_^
例如這題用 BASH 來解,只要...... 一行

引用:
cat "文章內容"|tr A-Z a-z|tr -c [^a-z] '\n'|grep -v ^$|sort|uniq -c|sort -k1,1nr|head -n 3
輸出結果:
引用:
   11 the
   5 ford
   5 president


第二題會比較刺激喔~~~
期待 Perl 的精彩演出~







====

可能有人覺得第一道題目很沒意義,我換個方式說大伙就知道這個可以用來做什麼。

題目:
請在 /var/log/secure LOG檔中找出嘗試入侵主機超過10次的IP,並在Firewall中封鎖該IP。

大伙是不是也漸漸感受到 BASH 的魔力 ^^?
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
舊 2006-12-28, 11:02 PM   #4 (permalink)
協調管理員
 
飛鳥 的頭像
榮譽勳章
UID - 23073
在線等級: 級別:72 | 在線時長:5513小時 | 升級還需:108小時級別:72 | 在線時長:5513小時 | 升級還需:108小時
註冊日期: 2003-01-07
VIP期限: 無限期
住址: 史萊姆團隊
文章: 7199
精華: 11
現金: 837 金幣
資產: 260029 金幣
預設

不算不算,又沒說可以用bash



嚴格來說,bash依賴作業系統,不能獨立於軟體,這一次不算數,第二題我也要用bash > <

第二題
引用:
cat xxx.txt |tr " " %|tr : " "|awk '{print $5}'|tr % " "|tr / " "|awk '{print $2","$1"\t"$3"\t"$4}'|sort
多做了幾個步驟啦,哈~

此帖於 2006-12-29 12:00 AM 被 飛鳥 編輯.
飛鳥 目前離線  
送花文章: 11706, 收花文章: 3363 篇, 收花: 16453 次
回覆時引用此帖
舊 2006-12-29, 01:23 AM   #5 (permalink)
註冊會員
 
snoopy 的頭像
榮譽勳章
UID - 33737
在線等級: 級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時
註冊日期: 2003-02-02
VIP期限: 2011-06
住址: 台南共和國
文章: 1831
精華: 0
現金: 12744 金幣
資產: 12834 金幣
預設

語法:
import java.util.Arrays;

public class Slime {
	public static void main(String[] args) {
		String src = "WASHINGTON - Gerald R. Ford was a man of limited ambition who, through bizarre circumstances never before experienced by the country, achieved an office that others win through the greatest determination and calculation. The nation's 38th president, Ford wanted only to become speaker of the House. History had another place for him. ADVERTISEMENT Ford was comfortable in the House, representing a Michigan congressional district for 25 years, rising to Republican leader and working toward his dream of one day running the chamber, when President Nixon called.He needed a new vice president; scandal had chased Spiro Agnew from the office.Ford wasn't Nixon's first choice, but the president agreed that the amiable Republican would be the easiest to win confirmation by both houses of Congress. So it went, and Ford became vice president in December 1973.Yet eight months later, the scenario got even stranger.";
		String[] array = src.replaceAll("\\W", " ").split("\\s+");
		Arrays.sort(array);
		int n = 1;
		for (int i = 0; i < array.length - 1; i++) {
			if (array[i].equals(array[i + 1])) {
				n++;
			} else {
				System.out.println(n + " " + array[i]);
				n = 1;
			}
		}
	}
}
輸出
語法:
頻率 字
1 1973
1 25
1 38th
1 ADVERTISEMENT
1 Agnew
1 Congress
1 December
5 Ford
1 Gerald
1 He
1 History
2 House
1 Michigan
2 Nixon
1 President
1 R
2 Republican
1 So
1 Spiro
1 The
1 WASHINGTON
1 Yet
3 a
1 achieved
1 agreed
1 ambition
1 amiable
1 an
3 and
1 another
1 be
1 became
1 become
1 before
1 bizarre
1 both
1 but
2 by
1 calculation
1 called
1 chamber
1 chased
1 choice
1 circumstances
1 comfortable
1 confirmation
1 congressional
1 country
1 day
1 determination
1 district
1 dream
1 easiest
1 eight
1 even
1 experienced
1 first
2 for
1 from
1 got
1 greatest
2 had
1 him
1 his
1 houses
2 in
1 it
1 later
1 leader
1 limited
1 man
1 months
1 nation
1 needed
1 never
1 new
4 of
2 office
1 one
1 only
1 others
1 place
4 president
1 representing
1 rising
1 running
2 s
1 scandal
1 scenario
1 speaker
1 stranger
1 t
2 that
10 the
2 through
3 to
1 toward
2 vice
1 wanted
2 was
1 wasn
1 went
1 when
1 who
2 win
1 working
1 would
snoopy 目前離線  
送花文章: 623, 收花文章: 392 篇, 收花: 1288 次
回覆時引用此帖
向 snoopy 送花的會員:
Chin-Wei (2006-12-29)
感謝您發表一篇好文章
舊 2006-12-29, 01:49 AM   #6 (permalink)
註冊會員
 
snoopy 的頭像
榮譽勳章
UID - 33737
在線等級: 級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時級別:49 | 在線時長:2676小時 | 升級還需:24小時
註冊日期: 2003-02-02
VIP期限: 2011-06
住址: 台南共和國
文章: 1831
精華: 0
現金: 12744 金幣
資產: 12834 金幣
預設

語法:
import java.util.Arrays;

public class Slime {
	public static void main(String[] args) {
		String str1 = "uucp:x:12:14:Adrian W. Jones/OFFICE_01/TEL_NUM_01";
		String str2 = "operator:x:13:0:Dorothy Gale/OFFICE_02/TEL_NUM_02";
		String str3 = "games:x:12:140:John Hancock/OFFICE_03/TEL_NUM_03";
		str1 = str1.substring(str1.lastIndexOf(":")+1,str1.length()).replaceAll("/", "\t");
		str2 = str2.substring(str2.lastIndexOf(":")+1,str2.length()).replaceAll("/", "\t");
		str3 = str3.substring(str3.lastIndexOf(":")+1,str3.length()).replaceAll("/", "\t");
		String[] str = {str1,str2,str3};
		Arrays.sort(str);
		for(int i=0;i<3;i++)
			System.out.println(str[i]);
	}
}

名字沒有多加處理
看不太懂 rule
不過那個也不難 加一個 method
call一下 大概多兩三行而已
snoopy 目前離線  
送花文章: 623, 收花文章: 392 篇, 收花: 1288 次
回覆時引用此帖
向 snoopy 送花的會員:
Chin-Wei (2006-12-29)
感謝您發表一篇好文章
舊 2006-12-29, 08:55 AM   #7 (permalink)
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設

引用:
作者: 飛鳥
不算不算,又沒說可以用bash

嚴格來說,bash依賴作業系統,不能獨立於軟體,這一次不算數,第二題我也要用bash > <

偶有說耶 ...... ↓↓↓↓↓↓↓↓↓↓
引用:
不限任何程式語言,歡迎大家來挑戰,雖然就算解出來了也沒獎品就是了 = =a

阿鳥老大別哭喔.... 團長給泥秀秀
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
舊 2006-12-29, 09:05 AM   #8 (permalink)
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設

引用:
作者: 飛鳥
第二題

多做了幾個步驟啦,哈~
阿鳥老大..... 第二題錯了 =.=

阿鳥的答案跑出來的結果:
引用:
Gale,Dorothy OFFICE_02 TEL_NUM_02
Hancock,John OFFICE_03 TEL_NUM_03
W.,Adrian Jones OFFICE_01
(紅色的部份有錯)


但題目要求的是:
引用:
Gale, Dorothy   <TAB>OFFICE_02<TAB>TEL_NUM_02
Hancock, John  <TAB>OFFICE_03<TAB>TEL_NUM_03
Jones, Adrian W. <TAB>OFFICE_01<TAB>TEL_NUM_01
阿鳥老大再接再力 ^^
如果這題這麼簡單偶就不會問了喔..........
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
舊 2006-12-29, 09:28 AM   #9 (permalink)
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設

引用:
作者: snoopy
名字沒有多加處理
看不太懂 rule
不過那個也不難 加一個 method
call一下 大概多兩三行而已

不對,你和阿鳥的答案都不對,要再加油喔 ^^
http://img402.imageshack.us/img402/7226/1qc5.jpg
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
舊 2006-12-29, 09:34 AM   #10 (permalink)
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設

大家要加油啊~ 這二題基本題解決了,偶才能接著問進階實戰題型啊 XD
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
舊 2006-12-29, 09:40 AM   #11 (permalink)
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設

引用:
作者: snoopy
[code]
import java.util.Arrays;

public class Slime {
public static void main(String[] args) {
String src = "WASHINGTON - Gerald R. Ford was a man of limited ambition who, through bizarre circumstances never before experienced by the country, achieved an office that others win through the greatest determination and calculation. The nation's 38th president, Ford wanted only to become speaker of the House. History had another place for him. ADVERTISEMENT Ford was comfortable in the House, representing a Michigan congressional district for 25 years, rising to Republican leader and working...

要排序啦 XD >__<

別和阿鳥一樣偷懶咩 XD
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
舊 2006-12-29, 10:18 AM   #12 (permalink)
協調管理員
 
飛鳥 的頭像
榮譽勳章
UID - 23073
在線等級: 級別:72 | 在線時長:5513小時 | 升級還需:108小時級別:72 | 在線時長:5513小時 | 升級還需:108小時
註冊日期: 2003-01-07
VIP期限: 無限期
住址: 史萊姆團隊
文章: 7199
精華: 11
現金: 837 金幣
資產: 260029 金幣
預設

那有,我明明就可以

引用:
[root@moonlight-glass root]# cat 123.txt
uucp:x:12:14:AdrianW. Jones/OFFICE_01/TEL_NUM_01
operator:x:13:0orothy Gale/OFFICE_02/TEL_NUM_02
games:x:12:140:John Hancock/OFFICE_03/TEL_NUM_03
[root@moonlight-glass root]#
[root@moonlight-glass root]#
[root@moonlight-glass root]#
[root@moonlight-glass root]# cat 123.txt |tr " " %|tr : " "|awk '{print $5}'|tr % " "|tr / " "|awk '{print $2","$1"\t"$3"\t"$4}'|sort
Gale,Dorothy OFFICE_02 TEL_NUM_02
Hancock,John OFFICE_03 TEL_NUM_03
Jones,AdrianW. OFFICE_01 TEL_NUM_01
飛鳥 目前離線  
送花文章: 11706, 收花文章: 3363 篇, 收花: 16453 次
回覆時引用此帖
舊 2006-12-29, 10:26 AM   #13 (permalink)
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設

引用:
作者: 飛鳥
那有,我明明就可以
阿鳥的輸出格式有誤......
仔細看,不太正確,讓空白的地方沒有空白,不該有逗點的地方卻有逗點 ^_^


泥的答案在偶的機子上跑出來的結果...
====
Gale,Dorothy OFFICE_02 TEL_NUM_02
Hancock,John OFFICE_03 TEL_NUM_03
W.,Adrian Jones OFFICE_01
====





==
這二大題難就難在輸出格式,如果大家都不照格式去寫,那這就失去它的意義
總之,該排序的地方就要排序,格式要注意的地方就得注意,不然偶就白問了 = =a
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
舊 2006-12-29, 11:08 AM   #14 (permalink)
協調管理員
 
飛鳥 的頭像
榮譽勳章
UID - 23073
在線等級: 級別:72 | 在線時長:5513小時 | 升級還需:108小時級別:72 | 在線時長:5513小時 | 升級還需:108小時
註冊日期: 2003-01-07
VIP期限: 無限期
住址: 史萊姆團隊
文章: 7199
精華: 11
現金: 837 金幣
資產: 260029 金幣
預設

我用手打錯,是
Adrian W. Jones

我打
AdrianW. Jones

少一個白鍵
飛鳥 目前離線  
送花文章: 11706, 收花文章: 3363 篇, 收花: 16453 次
回覆時引用此帖
舊 2006-12-29, 11:39 AM   #15 (permalink)
長老會員
 
Chin-Wei 的頭像
榮譽勳章
UID - 114112
在線等級: 級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時級別:14 | 在線時長:257小時 | 升級還需:28小時
註冊日期: 2007-02-18
文章: 3448
精華: 0
現金: 1674 金幣
資產: 32804 金幣
預設

引用:
作者: 飛鳥
我用手打錯,是
Adrian W. Jones

我打
AdrianW. Jones

少一個白鍵

阿鳥的答案在偶的機子上跑出來是長這樣耶...

====
Gale,Dorothy OFFICE_02 TEL_NUM_02
Hancock,John OFFICE_03 TEL_NUM_03
W.,Adrian Jones OFFICE_01
====


還是 portability 的問題?
Chin-Wei 目前離線  
送花文章: 5387, 收花文章: 1361 篇, 收花: 5457 次
回覆時引用此帖
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用


所有時間均為台北時間。現在的時間是 03:21 AM


Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.


SEO by vBSEO 3.6.1